Skip to content

Commit 129d996

Browse files
committed
Fix failing test cases due to inaccurate timers
1 parent 1854d5d commit 129d996

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

tests/AbstractLoopTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ public function testSignalsKeepTheLoopRunning()
727727
$loop->stop();
728728
});
729729

730-
$this->assertRunSlowerThan(1.5);
730+
$this->assertRunSlowerThan(1.4);
731731
}
732732

733733
/**

tests/Timer/AbstractTimerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public function testAddTimerWillBeInvokedOnceAndBlocksLoopWhenRunning()
2626
{
2727
$loop = $this->createLoop();
2828

29-
$loop->addTimer(0.002, $this->expectCallableOnce());
29+
$loop->addTimer(0.005, $this->expectCallableOnce());
3030

3131
$start = microtime(true);
3232
$loop->run();
3333
$end = microtime(true);
3434

35-
// 1 invocation should take 2ms1ms due to timer inaccuracies)
35+
// 1 invocation should take 5msa few milliseconds due to timer inaccuracies)
3636
// make no strict assumptions about time interval, must at least take 1ms
3737
// and should not take longer than 0.1s for slower loops.
3838
$this->assertGreaterThanOrEqual(0.001, $end - $start);
@@ -57,7 +57,7 @@ public function testAddPeriodicTimerWillBeInvokedUntilItIsCancelled()
5757

5858
// make no strict assumptions about actual time interval.
5959
// leave some room to ensure this ticks exactly 3 times.
60-
$loop->addTimer(0.399, function () use ($loop, $periodic) {
60+
$loop->addTimer(0.350, function () use ($loop, $periodic) {
6161
$loop->cancelTimer($periodic);
6262
});
6363

@@ -135,7 +135,7 @@ function () use (&$start) {
135135
$loop->run();
136136
$end = \microtime(true);
137137

138-
// 1ms should be enough even on slow machines
139-
$this->assertLessThan(0.001, $end - $start);
138+
// 1ms should be enough even on slow machines (± 1ms due to timer inaccuracies)
139+
$this->assertLessThan(0.002, $end - $start);
140140
}
141141
}

0 commit comments

Comments
 (0)