1
0
mirror of https://github.com/danog/loop.git synced 2024-12-02 09:17:51 +01:00

Cleanup tests

This commit is contained in:
Daniil Gentili 2022-12-24 18:49:23 +01:00
parent 980b386cd8
commit df52bbc7bf
3 changed files with 25 additions and 25 deletions

View File

@ -9,11 +9,9 @@
namespace danog\Loop\Test; namespace danog\Loop\Test;
use Amp\Future;
use Amp\PHPUnit\AsyncTestCase; use Amp\PHPUnit\AsyncTestCase;
use danog\Loop\Test\Interfaces\BasicInterface; use danog\Loop\Test\Interfaces\BasicInterface;
use function Amp\async;
use function Amp\delay; use function Amp\delay;
/** /**
@ -22,13 +20,6 @@ use function Amp\delay;
abstract class Fixtures extends AsyncTestCase abstract class Fixtures extends AsyncTestCase
{ {
const LOOP_NAME = 'TTTT'; const LOOP_NAME = 'TTTT';
/**
* Check if promise has been resolved afterwards.
*/
protected static function isResolved(Future $promise): bool
{
return $promise->isComplete();
}
/** /**
* Execute pre-start assertions. * Execute pre-start assertions.
* *
@ -52,11 +43,14 @@ abstract class Fixtures extends AsyncTestCase
* *
* @param BasicInterface $loop Loop * @param BasicInterface $loop Loop
* @param bool $running Whether we should expect the loop to be running * @param bool $running Whether we should expect the loop to be running
* @param bool $running Whether we should actually start the loop by returning control to the event loop
* *
*/ */
protected function assertAfterStart(BasicInterface $loop, bool $running = true): void protected function assertAfterStart(BasicInterface $loop, bool $running = true, bool $start = true): void
{ {
delay(0.001); if ($start) {
delay(0.001);
}
$this->assertTrue($loop->inited()); $this->assertTrue($loop->inited());
if ($running) { if ($running) {

View File

@ -43,13 +43,14 @@ class LoopTest extends Fixtures
/** /**
* Test basic exception in loop. * Test basic exception in loop.
* *
* @param BasicInterface $loop Loop
* *
* *
* @dataProvider provideBasicExceptions * @dataProvider provideBasicExceptions
*/ */
/*public function testException(BasicInterface $loop): void public function testException(BasicInterface $loop): void
{ {
$this->markTestSkipped();
$this->expectException(\RuntimeException::class); $this->expectException(\RuntimeException::class);
$this->assertPreStart($loop); $this->assertPreStart($loop);
@ -61,7 +62,7 @@ class LoopTest extends Fixtures
$this->assertEquals(1, $loop->startCounter()); $this->assertEquals(1, $loop->startCounter());
$this->assertEquals(1, $loop->endCounter()); $this->assertEquals(1, $loop->endCounter());
}*/ }
/** /**
* Provide loop implementations. * Provide loop implementations.

View File

@ -14,6 +14,7 @@ use danog\Loop\ResumableLoop;
use danog\Loop\ResumableSignalLoop; use danog\Loop\ResumableSignalLoop;
use danog\Loop\Test\Interfaces\ResumableInterface; use danog\Loop\Test\Interfaces\ResumableInterface;
use danog\Loop\Test\Traits\Resumable; use danog\Loop\Test\Traits\Resumable;
use Generator;
use function Amp\delay; use function Amp\delay;
@ -37,7 +38,7 @@ class ResumableTest extends Fixtures
$this->assertAfterStart($loop); $this->assertAfterStart($loop);
delay(0.010); delay(0.010);
$this->assertTrue(self::isResolved($paused)); $this->assertTrue($paused->isComplete());
delay(0.1); delay(0.1);
$this->assertFinal($loop); $this->assertFinal($loop);
@ -60,7 +61,7 @@ class ResumableTest extends Fixtures
$this->assertTrue($loop->start()); $this->assertTrue($loop->start());
delay(0.001); delay(0.001);
$this->assertFalse(self::isResolved($paused)); // Did not pause $this->assertFalse($paused->isComplete()); // Did not pause
// Invert the order as the afterTest assertions will begin the test anew // Invert the order as the afterTest assertions will begin the test anew
$this->assertFinal($loop); $this->assertFinal($loop);
@ -90,7 +91,7 @@ class ResumableTest extends Fixtures
$this->assertAfterStart($loop); $this->assertAfterStart($loop);
delay(0.001); delay(0.001);
$this->assertTrue(self::isResolved($paused)); // Did pause $this->assertTrue($paused->isComplete()); // Did pause
$paused = $deferred ? $loop->resumeDefer() : $loop->resume(); $paused = $deferred ? $loop->resumeDefer() : $loop->resume();
if ($deferred) { if ($deferred) {
@ -100,7 +101,7 @@ class ResumableTest extends Fixtures
$this->assertFinal($loop); $this->assertFinal($loop);
delay(0.001); delay(0.001);
$this->assertFalse(self::isResolved($paused)); // Did not pause again $this->assertFalse($paused->isComplete()); // Did not pause again
} }
/** /**
@ -124,18 +125,22 @@ class ResumableTest extends Fixtures
$this->assertAfterStart($loop); $this->assertAfterStart($loop);
delay(0.001); delay(0.001);
$this->assertTrue(self::isResolved($paused1)); // Did pause $this->assertTrue($paused1->isComplete()); // Did pause
$this->assertTrue(self::isResolved($paused2)); // Did pause $this->assertTrue($paused2->isComplete()); // Did pause
$paused1 = $loop->resumeDeferOnce(); $paused1 = $loop->resumeDeferOnce();
$paused2 = $loop->resumeDeferOnce(); $paused2 = $loop->resumeDeferOnce();
$this->assertAfterStart($loop);
$this->assertFalse($paused1->isComplete()); // Did not pause again
$this->assertFalse($paused2->isComplete()); // Did not pause again
$this->assertAfterStart($loop, true, false);
delay(0.001); delay(0.001);
$this->assertFinal($loop); $this->assertFinal($loop);
delay(0.001); delay(0.001);
$this->assertFalse(self::isResolved($paused1)); // Did not pause again $this->assertFalse($paused1->isComplete()); // Did not pause again
$this->assertFalse(self::isResolved($paused2)); // Did not pause again $this->assertFalse($paused2->isComplete()); // Did not pause again
} }
/** /**
@ -160,14 +165,14 @@ class ResumableTest extends Fixtures
* *
* *
*/ */
public function provideResumableInterval(): void public function provideResumableInterval(): Generator
{ {
foreach ([true, false] as $deferred) { foreach ([true, false] as $deferred) {
foreach ([10000, null] as $interval) { foreach ([10000, null] as $interval) {
foreach ($this->provideResumable() as $params) { foreach ($this->provideResumable() as $params) {
$params[] = $interval; $params[] = $interval;
$params[] = $deferred; $params[] = $deferred;
$params; yield $params;
} }
} }
} }