Skip to content

Commit 2180ce3

Browse files
author
Greg Bowler
committed
Test actual loop delay is accurate
1 parent 5753a55 commit 2180ce3

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

test/phpunit/LoopTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,18 @@ public function testHalt() {
156156
$sut->run();
157157
self::assertEquals(10, $tickCount);
158158
}
159+
160+
public function testSleepActuallyDelays() {
161+
$startEpoch = microtime(true);
162+
$waitUntil = $startEpoch + 0.25;
163+
164+
$sut = new Loop();
165+
$sut->waitUntil($waitUntil);
166+
$endEpoch = microtime(true);
167+
self::assertEquals(
168+
// The delay should be accurate to a hundredth of a second.
169+
round($waitUntil, 2),
170+
round($endEpoch, 2)
171+
);
172+
}
159173
}

0 commit comments

Comments
 (0)