Skip to content
Browse files

test of watching plain files with Linux::Inotify2

  • Loading branch information...
1 parent 1520b64 commit fc60d25ebd3324eeb23738c839a0e5e0ed67994a @sunnavy committed Jan 19, 2012
Showing with 52 additions and 0 deletions.
  1. +52 −0 t/plain_file_with_inotify2.t
View
52 t/plain_file_with_inotify2.t
@@ -0,0 +1,52 @@
+use strict;
+use warnings;
+
+use Filesys::Notify::Simple;
+use Test::More;
+use FindBin;
+
+eval { require Linux::Inotify2 };
+
+plan skip_all => 'Linux::Inotify2 is required to run this test' if $@;
+
+my $test_file = "$FindBin::Bin/x/plain_file_for_inotify2.data";
+open my $out, ">", $test_file;
+print $out "foo" . time;
+close $out;
+
+my $w = Filesys::Notify::Simple->new( [$test_file] );
+
+my $pid = fork;
+if ( $pid == 0 ) {
+ sleep 3;
+
+ unlink $test_file;
+
+ my $other_file = "$FindBin::Bin/x/bar";
+ open $out, ">", $other_file;
+ print $out "bar" . time;
+ close $out;
+
+ exit;
+}
+elsif ( $pid != 0 ) {
+ my $event;
+
+ local $SIG{ALRM} = sub { return };
+ alarm 10;
+
+ $w->wait( sub { $event = shift } );
+ like $event->{path}, qr/plain_file_for_inotify2/,
+ 'first event is from watched file';
+
+ $w->wait( sub { $event = shift } );
+ is $event, undef, 'only one event';
+
+ waitpid $pid, 0;
+}
+else {
+ die $!;
+}
+
+done_testing();
+

0 comments on commit fc60d25

Please sign in to comment.
Something went wrong with that request. Please try again.