mirror of
https://github.com/danog/loop.git
synced 2024-11-30 04:19:04 +01:00
Cleanup tests
This commit is contained in:
parent
980b386cd8
commit
df52bbc7bf
@ -9,11 +9,9 @@
|
||||
|
||||
namespace danog\Loop\Test;
|
||||
|
||||
use Amp\Future;
|
||||
use Amp\PHPUnit\AsyncTestCase;
|
||||
use danog\Loop\Test\Interfaces\BasicInterface;
|
||||
|
||||
use function Amp\async;
|
||||
use function Amp\delay;
|
||||
|
||||
/**
|
||||
@ -22,13 +20,6 @@ use function Amp\delay;
|
||||
abstract class Fixtures extends AsyncTestCase
|
||||
{
|
||||
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.
|
||||
*
|
||||
@ -52,11 +43,14 @@ abstract class Fixtures extends AsyncTestCase
|
||||
*
|
||||
* @param BasicInterface $loop Loop
|
||||
* @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
|
||||
{
|
||||
if ($start) {
|
||||
delay(0.001);
|
||||
}
|
||||
$this->assertTrue($loop->inited());
|
||||
|
||||
if ($running) {
|
||||
|
@ -43,13 +43,14 @@ class LoopTest extends Fixtures
|
||||
/**
|
||||
* Test basic exception in loop.
|
||||
*
|
||||
* @param BasicInterface $loop Loop
|
||||
*
|
||||
*
|
||||
* @dataProvider provideBasicExceptions
|
||||
*/
|
||||
/*public function testException(BasicInterface $loop): void
|
||||
public function testException(BasicInterface $loop): void
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$this->assertPreStart($loop);
|
||||
@ -61,7 +62,7 @@ class LoopTest extends Fixtures
|
||||
|
||||
$this->assertEquals(1, $loop->startCounter());
|
||||
$this->assertEquals(1, $loop->endCounter());
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide loop implementations.
|
||||
|
@ -14,6 +14,7 @@ use danog\Loop\ResumableLoop;
|
||||
use danog\Loop\ResumableSignalLoop;
|
||||
use danog\Loop\Test\Interfaces\ResumableInterface;
|
||||
use danog\Loop\Test\Traits\Resumable;
|
||||
use Generator;
|
||||
|
||||
use function Amp\delay;
|
||||
|
||||
@ -37,7 +38,7 @@ class ResumableTest extends Fixtures
|
||||
$this->assertAfterStart($loop);
|
||||
|
||||
delay(0.010);
|
||||
$this->assertTrue(self::isResolved($paused));
|
||||
$this->assertTrue($paused->isComplete());
|
||||
delay(0.1);
|
||||
|
||||
$this->assertFinal($loop);
|
||||
@ -60,7 +61,7 @@ class ResumableTest extends Fixtures
|
||||
$this->assertTrue($loop->start());
|
||||
|
||||
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
|
||||
$this->assertFinal($loop);
|
||||
@ -90,7 +91,7 @@ class ResumableTest extends Fixtures
|
||||
$this->assertAfterStart($loop);
|
||||
|
||||
delay(0.001);
|
||||
$this->assertTrue(self::isResolved($paused)); // Did pause
|
||||
$this->assertTrue($paused->isComplete()); // Did pause
|
||||
|
||||
$paused = $deferred ? $loop->resumeDefer() : $loop->resume();
|
||||
if ($deferred) {
|
||||
@ -100,7 +101,7 @@ class ResumableTest extends Fixtures
|
||||
$this->assertFinal($loop);
|
||||
|
||||
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);
|
||||
|
||||
delay(0.001);
|
||||
$this->assertTrue(self::isResolved($paused1)); // Did pause
|
||||
$this->assertTrue(self::isResolved($paused2)); // Did pause
|
||||
$this->assertTrue($paused1->isComplete()); // Did pause
|
||||
$this->assertTrue($paused2->isComplete()); // Did pause
|
||||
|
||||
$paused1 = $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);
|
||||
$this->assertFinal($loop);
|
||||
|
||||
delay(0.001);
|
||||
$this->assertFalse(self::isResolved($paused1)); // Did not pause again
|
||||
$this->assertFalse(self::isResolved($paused2)); // Did not pause again
|
||||
$this->assertFalse($paused1->isComplete()); // 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 ([10000, null] as $interval) {
|
||||
foreach ($this->provideResumable() as $params) {
|
||||
$params[] = $interval;
|
||||
$params[] = $deferred;
|
||||
$params;
|
||||
yield $params;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user