Skip to content

Commit

Permalink
Tests for timing related scheduler methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Oct 30, 2013
1 parent aa0f747 commit d81e6df
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion S17-concurrency/scheduler.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 7;
plan 10;

ok $*SCHEDULER ~~ Scheduler, "Default scheduler does Scheduler role";

Expand Down Expand Up @@ -52,3 +52,23 @@ ok $*SCHEDULER ~~ Scheduler, "Default scheduler does Scheduler role";
1 while $*SCHEDULER.outstanding;
is $tracker, "scheduled,", "Handler not run if no error";
}

{
# Timing related tests are always a tad fragile, e.g. on a loaded system.
# Hopefully the times are enough leeway.
my $tracker = '';
$*SCHEDULER.schedule_in({ $tracker ~= '2s'; }, 2);
$*SCHEDULER.schedule_in({ $tracker ~= '1s'; }, 1);
is $tracker, '', "schedule_in doesn't schedule immediately";
sleep 3;
is $tracker, "1s2s", "Timer tasks ran in right order";
}

{
# Also at risk of being a little fragile, but again hopefully Ok on all
# but the most ridiculously loaded systems.
my $a = 0;
$*SCHEDULER.schedule_every({ $a++ }, 0.1);
sleep 1;
ok 5 < $a < 15, "schedule_every schedules repeatedly";
}

0 comments on commit d81e6df

Please sign in to comment.