1
0
mirror of https://github.com/danog/loop.git synced 2024-11-26 11:54:51 +01:00

Improve coverage

This commit is contained in:
Daniil Gentili 2023-01-23 13:11:46 +01:00
parent da08301a91
commit 4b2a24e3db
2 changed files with 19 additions and 9 deletions

View File

@ -80,8 +80,20 @@ abstract class Loop implements Stringable
if (!$this->running) {
return false;
}
$this->resume();
$this->running = false;
if ($this->resumeTimer) {
$storedWatcherId = $this->resumeTimer;
EventLoop::cancel($storedWatcherId);
$this->resumeTimer = null;
}
if ($this->resumeImmediate) {
$storedWatcherId = $this->resumeImmediate;
EventLoop::cancel($storedWatcherId);
$this->resumeTimer = null;
}
if ($this->paused) {
$this->exitedLoop();
}
return true;
}
abstract protected function loop(): ?float;
@ -123,11 +135,7 @@ abstract class Loop implements Stringable
private function exitedLoopInternal(): void
{
$this->running = false;
if ($this->resumeTimer) {
$storedWatcherId = $this->resumeTimer;
EventLoop::cancel($storedWatcherId);
$this->resumeTimer = null;
}
\assert($this->resumeTimer === null);
if ($this->resumeImmediate) {
$storedWatcherId = $this->resumeImmediate;
EventLoop::cancel($storedWatcherId);

View File

@ -164,7 +164,7 @@ class GenericTest extends AsyncTestCase
$this->assertEquals(0.1, $loop->getLastPause());
$this->assertTrue($loop->resume());
delay(0.002);
delay(0.003);
$this->assertEquals(4, $runCount);
$this->assertEquals(4, $loop->getPauseCount());
@ -181,10 +181,12 @@ class GenericTest extends AsyncTestCase
$this->assertEquals(4, $loop->getPauseCount());
$this->assertEquals(0.1, $loop->getLastPause());
$this->assertFalse($loop->isRunning());
$this->assertEquals(1, $loop->startCounter());
$this->assertEquals(1, $loop->endCounter());
$this->assertFalse($loop->isRunning());
$this->assertFalse($loop->stop());
$this->assertFalse($loop->resume());
}
/**