Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Move "testTimerIntervalBelowZeroRunsImmediately" from AbstractLoopTes…
…t to AbstractTimerTest
  • Loading branch information
PabloKowalczyk committed Aug 5, 2019
commit a3165da14fcf467518445be4a0bd794d96cf5ce9
7 changes: 0 additions & 7 deletions tests/AbstractLoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,13 +589,6 @@ public function testSignalsKeepTheLoopRunningAndRemovingItStopsTheLoop()
$this->assertRunFasterThan(1.6);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently have this odd split in our tests suite, can you move this to the similar tests in AbstractTimerTests?

Other than that, this test looks good to me, but we've seen similar tests fail sporadically due to timer inaccuracies, see also

public function testAddTimerWillBeInvokedOnceAndBlocksLoopWhenRunning()
{
// Make no strict assumptions about actual time interval. Common
// environments usually provide millisecond accuracy (or better), but
// Travis and other CI systems are slow.
// We try to compensate for this by skipping accurate tests when the
// current platform is known to be inaccurate. We test this by sleeping
// 3x1ms and then measure the time for each iteration before running the
// actual test.
for ($i = 0; $i < 3; ++$i) {
$start = microtime(true);
usleep(1000);
$time = microtime(true) - $start;
if ($time < 0.001 || $time > 0.002) {
$this->markTestSkipped('Platform provides insufficient accuracy (' . $time . ' s)');
}
}

Perhaps you can update this to use a similar logic to make sure an inaccurate platform does not cause this test to fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved.


public function testTimerIntervalBelowZeroRunsImmediately()
{
$this->loop->addTimer(-1, function () {});

$this->assertRunFasterThan(0.002);
}

public function testTimerIntervalCanBeFarInFuture()
{
// Maximum interval for ExtUvLoop implementation
Expand Down
18 changes: 18 additions & 0 deletions tests/Timer/AbstractTimerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,22 @@ public function testMinimumIntervalOneMicrosecond()

$this->assertEquals(0.000001, $timer->getInterval());
}

public function testTimerIntervalBelowZeroRunsImmediately()
{
$loop = $this->createLoop();
$start = 0;
$loop->addTimer(
-1,
function () use (&$start) {
$start = \microtime(true);
}
);

$loop->run();
$end = \microtime(true);

// 1ms should be enough even on slow machines
$this->assertLessThan(0.001, $end - $start);
}
}