Skip to content

Commit 9ca917b

Browse files
committed
Make polling interval configurable
And use it to speed up unit tests
1 parent aedb877 commit 9ca917b

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

lib/Filesys/Notify/Simple.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package Filesys::Notify::Simple;
33
use strict;
44
use 5.008_001;
55
our $VERSION = '0.12';
6+
our $interval = 2.0;
67

78
use Carp ();
89
use Cwd;
@@ -159,7 +160,8 @@ sub wait_timer {
159160
my $cb = shift;
160161
my @events;
161162
while (1) {
162-
sleep 2;
163+
# sleep 0 is needed to fix sigalrm on windows!?
164+
select undef, undef, undef, $interval && sleep 0;
163165
my $new_fs = _full_scan(@path);
164166
_compare_fs($fs, $new_fs, sub { push @events, { path => $_[0] } });
165167
$fs = $new_fs;

t/empty_dir.t

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,30 @@ plan tests => 6;
1010

1111
my $dir = tempdir( DIR => "$FindBin::Bin/x" );
1212
my $w = Filesys::Notify::Simple->new([ "$dir" ]);
13+
$Filesys::Notify::Simple::interval = 0.5;
1314

1415
mkdir "$dir/root";
1516

1617

1718
my $pid = fork;
1819
if ($pid == 0) {
1920
Test::SharedFork->child;
20-
sleep 3;
21+
sleep 1;
2122
note "mkdir subroot\n";
2223
mkdir "$dir/subroot";
23-
sleep 3;
24+
sleep 1;
2425
note "mkdir subroot/deep\n";
2526
mkdir "$dir/subroot/deep";
26-
sleep 3;
27+
sleep 1;
2728
note "mkdir subroot/deep/down\n";
2829
mkdir "$dir/subroot/deep/down";
29-
sleep 3;
30+
sleep 1;
3031
note "rmdir subroot/deep/down\n";
3132
rmdir "$dir/subroot/deep/down";
32-
sleep 3;
33+
sleep 1;
3334
note "rmdir subroot/deep\n";
3435
rmdir "$dir/subroot/deep";
35-
sleep 3;
36+
sleep 1;
3637
note "rmdir subroot\n";
3738
rmdir "$dir/subroot";
3839
} elsif ($pid != 0) {

t/move.t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plan tests => 2;
1010

1111
my $dir = tempdir( DIR => "$FindBin::Bin/x" );
1212
my $w = Filesys::Notify::Simple->new([ "lib", "$dir" ]);
13+
$Filesys::Notify::Simple::interval = 0.5;
1314

1415
my $test_file = "$dir/move_create.data";
1516
my $test_file_to = "$dir/move_create.data.to";
@@ -18,11 +19,11 @@ my $test_file_to = "$dir/move_create.data.to";
1819
my $pid = fork;
1920
if ($pid == 0) {
2021
Test::SharedFork->child;
21-
sleep 3;
22+
sleep 1;
2223
open my $out, ">", $test_file;
2324
print $out "foo" . time;
2425
close $out;
25-
sleep 3;
26+
sleep 1;
2627
rename($test_file => $test_file_to);
2728
} elsif ($pid != 0) {
2829
Test::SharedFork->parent;

t/non_existent_path.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ $ENV{PERL_FNS_NO_OPT} = 1;
55
require Filesys::Notify::Simple;
66

77
my $fs = Filesys::Notify::Simple->new(["/xxx/nonexistent"]);
8+
$Filesys::Notify::Simple::interval = 0.5;
89

910
eval {
1011
$SIG{ALRM} = sub { die "Alarm\n" };

t/rm_create.t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use FindBin;
66
use File::Temp qw( tempdir );
77

88
my $dir = tempdir( DIR => "$FindBin::Bin/x" );
9+
$Filesys::Notify::Simple::interval = 0.5;
910

1011

1112
plan tests => 2;
@@ -15,12 +16,12 @@ my $w = Filesys::Notify::Simple->new([ "lib", "$dir" ]);
1516
my $pid = fork;
1617
if ($pid == 0) {
1718
Test::SharedFork->child;
18-
sleep 3;
19+
sleep 1;
1920
my $test_file = "$dir/rm_create.data";
2021
open my $out, ">", $test_file;
2122
print $out "foo" . time;
2223
close $out;
23-
sleep 3;
24+
sleep 1;
2425
unlink $test_file;
2526
} elsif ($pid != 0) {
2627
Test::SharedFork->parent;

0 commit comments

Comments
 (0)