'sleep' => sub {
diag 'Using sleep()-based fallback usleep()';
return sub ($) {
- my $s = int($_[0] / 1e6);
- my $t = sleep $s;
+ my $ms = int $_[0];
+ my $s = int($ms / 1e6) + ($ms % 1e6 == 0 ? 0 : 1);
+ my $t = sleep $s;
return $t * 1e6;
};
},
my @impls = qw<Time::HiRes select sleep>;
+my $duration = 1e5;
+
for my $impl (@impls) {
my $desc = "$impl-based usleep()";
{
eval 'defined &main::usleep';
};
ok $has_usleep, "$desc was imported";
- my $ret = usleep(1e6);
- cmp_ok $ret, '>=', 1e6, "$desc did sleep";
+ my $ret = usleep($duration);
+ cmp_ok $ret, '>=', $duration, "$desc did sleep";
diag "$desc actually slept $ret microseconds";
}