mirror of
https://github.com/danog/loop.git
synced 2024-11-30 04:19:04 +01:00
Test fixes
This commit is contained in:
parent
d4a3264eef
commit
ac1ad0f204
@ -9,16 +9,13 @@
|
||||
|
||||
namespace danog\Loop\Test;
|
||||
|
||||
use Amp\PHPUnit\AsyncTestCase;
|
||||
use danog\Loop\Loop;
|
||||
use danog\Loop\Test\Interfaces\BasicInterface;
|
||||
|
||||
use function Amp\delay;
|
||||
|
||||
/**
|
||||
* Fixtures.
|
||||
*/
|
||||
abstract class Fixtures extends AsyncTestCase
|
||||
abstract class Fixtures extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
const LOOP_NAME = 'TTTT';
|
||||
/**
|
||||
@ -46,7 +43,7 @@ abstract class Fixtures extends AsyncTestCase
|
||||
protected function assertAfterStart(BasicInterface&Loop $loop, bool $running = true, bool $start = true): void
|
||||
{
|
||||
if ($start) {
|
||||
delay(0.001);
|
||||
LoopTest::waitTick();
|
||||
}
|
||||
$this->assertTrue($loop->inited());
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
namespace danog\Loop\Test;
|
||||
|
||||
use Amp\PHPUnit\AsyncTestCase;
|
||||
use danog\Loop\GenericLoop;
|
||||
use danog\Loop\Loop;
|
||||
use danog\Loop\Test\Interfaces\LoggingPauseInterface;
|
||||
@ -18,7 +17,7 @@ use danog\Loop\Test\Traits\LoggingPause;
|
||||
|
||||
use function Amp\delay;
|
||||
|
||||
class GenericTest extends AsyncTestCase
|
||||
class GenericTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Test basic loop.
|
||||
@ -79,7 +78,6 @@ class GenericTest extends AsyncTestCase
|
||||
$pauseTime = GenericLoop::PAUSE;
|
||||
$callable = function (GenericLoop $loop) use (&$runCount, &$pauseTime, &$l) {
|
||||
$l = $loop;
|
||||
delay(0.001);
|
||||
$runCount++;
|
||||
return $pauseTime;
|
||||
};
|
||||
@ -91,7 +89,6 @@ class GenericTest extends AsyncTestCase
|
||||
public function run(GenericLoop $loop)
|
||||
{
|
||||
$this->loop = $loop;
|
||||
delay(0.001);
|
||||
$this->runCount++;
|
||||
return $this->pauseTime;
|
||||
}
|
||||
@ -104,7 +101,6 @@ class GenericTest extends AsyncTestCase
|
||||
public function run(GenericLoop $loop)
|
||||
{
|
||||
$this->loop = $loop;
|
||||
delay(0.001);
|
||||
$this->runCount++;
|
||||
return $this->pauseTime;
|
||||
}
|
||||
@ -145,7 +141,7 @@ class GenericTest extends AsyncTestCase
|
||||
$this->assertEquals(0, $loop->getPauseCount());
|
||||
|
||||
$this->assertTrue($loop->start());
|
||||
delay(0.003);
|
||||
LoopTest::waitTick();
|
||||
$this->fixtureStarted($loop);
|
||||
$expectedRunCount++;
|
||||
$this->assertEquals($loop, $l);
|
||||
@ -156,7 +152,7 @@ class GenericTest extends AsyncTestCase
|
||||
|
||||
$pauseTime = 0.1;
|
||||
$this->assertTrue($loop->resume());
|
||||
delay(0.002);
|
||||
LoopTest::waitTick();
|
||||
$this->fixtureStarted($loop);
|
||||
$expectedRunCount++;
|
||||
|
||||
@ -180,7 +176,7 @@ class GenericTest extends AsyncTestCase
|
||||
$this->assertEquals(0.1, $loop->getLastPause());
|
||||
|
||||
$this->assertTrue($loop->resume());
|
||||
delay(0.003);
|
||||
LoopTest::waitTick();
|
||||
$expectedRunCount++;
|
||||
|
||||
$this->assertEquals($expectedRunCount, $runCount);
|
||||
@ -194,7 +190,7 @@ class GenericTest extends AsyncTestCase
|
||||
$this->assertTrue($loop->resume());
|
||||
$expectedRunCount++;
|
||||
}
|
||||
delay(0.002);
|
||||
LoopTest::waitTick();
|
||||
$this->assertEquals($expectedRunCount, $runCount);
|
||||
$this->assertEquals(4, $loop->getPauseCount());
|
||||
$this->assertEquals(0.1, $loop->getLastPause());
|
||||
@ -209,7 +205,7 @@ class GenericTest extends AsyncTestCase
|
||||
// Restart loop
|
||||
$pauseTime = GenericLoop::PAUSE;
|
||||
$this->assertTrue($loop->start());
|
||||
delay(0.003);
|
||||
LoopTest::waitTick();
|
||||
$this->fixtureStarted($loop, 2);
|
||||
$expectedRunCount++;
|
||||
|
||||
@ -224,7 +220,7 @@ class GenericTest extends AsyncTestCase
|
||||
$this->assertTrue($loop->resume());
|
||||
$expectedRunCount++;
|
||||
}
|
||||
delay(0.002);
|
||||
LoopTest::waitTick();
|
||||
$this->assertEquals($expectedRunCount, $runCount);
|
||||
$this->assertEquals(5, $loop->getPauseCount());
|
||||
$this->assertEquals(0.0, $loop->getLastPause());
|
||||
@ -240,7 +236,7 @@ class GenericTest extends AsyncTestCase
|
||||
$pauseTime = GenericLoop::PAUSE;
|
||||
$this->assertTrue($loop->start());
|
||||
$this->assertTrue($loop->stop());
|
||||
delay(0.003);
|
||||
LoopTest::waitTick();
|
||||
|
||||
$this->assertEquals($expectedRunCount, $runCount);
|
||||
$this->assertEquals(5, $loop->getPauseCount());
|
||||
@ -257,7 +253,7 @@ class GenericTest extends AsyncTestCase
|
||||
$pauseTime = 1.0;
|
||||
$this->assertTrue($loop->start());
|
||||
$this->assertTrue($loop->stop());
|
||||
delay(0.003);
|
||||
LoopTest::waitTick();
|
||||
|
||||
$this->assertEquals($expectedRunCount, $runCount);
|
||||
$this->assertEquals(5, $loop->getPauseCount());
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
namespace danog\Loop\Test;
|
||||
|
||||
use Amp\PHPUnit\UnhandledException;
|
||||
use danog\Loop\Loop;
|
||||
use danog\Loop\Test\Interfaces\BasicInterface;
|
||||
use danog\Loop\Test\Traits\Basic;
|
||||
@ -19,6 +18,12 @@ use function Amp\delay;
|
||||
|
||||
class LoopTest extends Fixtures
|
||||
{
|
||||
public static function waitTick(): void
|
||||
{
|
||||
$f = new \Amp\DeferredFuture;
|
||||
\Revolt\EventLoop::defer(fn () => $f->complete());
|
||||
$f->getFuture()->await();
|
||||
}
|
||||
/**
|
||||
* Test basic loop.
|
||||
*/
|
||||
@ -51,7 +56,7 @@ class LoopTest extends Fixtures
|
||||
delay(0.1);
|
||||
$this->stop();
|
||||
$this->ran = true;
|
||||
return 10.0;
|
||||
return 1000.0;
|
||||
}
|
||||
};
|
||||
$this->assertPreStart($loop);
|
||||
@ -70,11 +75,11 @@ class LoopTest extends Fixtures
|
||||
$loop = new class() extends Loop implements BasicInterface {
|
||||
use BasicException;
|
||||
};
|
||||
$this->expectException(UnhandledException::class);
|
||||
$this->expectException(\Revolt\EventLoop\UncaughtThrowable::class);
|
||||
|
||||
$this->assertPreStart($loop);
|
||||
$this->assertTrue($loop->start());
|
||||
delay(0.001);
|
||||
self::waitTick();
|
||||
$this->assertFalse($loop->isRunning());
|
||||
|
||||
$this->assertTrue($loop->inited());
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
namespace danog\Loop\Test;
|
||||
|
||||
use Amp\PHPUnit\AsyncTestCase;
|
||||
use danog\Loop\Loop;
|
||||
use danog\Loop\PeriodicLoop;
|
||||
use danog\Loop\Test\Interfaces\LoggingInterface;
|
||||
@ -18,7 +17,7 @@ use danog\Loop\Test\Traits\Logging;
|
||||
|
||||
use function Amp\delay;
|
||||
|
||||
class PeriodicTest extends AsyncTestCase
|
||||
class PeriodicTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Test basic loop.
|
||||
@ -79,7 +78,6 @@ class PeriodicTest extends AsyncTestCase
|
||||
$retValue = false;
|
||||
$callable = function (?PeriodicLoop $loop) use (&$runCount, &$retValue, &$l) {
|
||||
$l = $loop;
|
||||
delay(0.001);
|
||||
$runCount++;
|
||||
return $retValue;
|
||||
};
|
||||
@ -91,7 +89,6 @@ class PeriodicTest extends AsyncTestCase
|
||||
public function run(?PeriodicLoop $loop)
|
||||
{
|
||||
$this->loop = $loop;
|
||||
delay(0.001);
|
||||
$this->runCount++;
|
||||
return $this->retValue;
|
||||
}
|
||||
@ -104,7 +101,6 @@ class PeriodicTest extends AsyncTestCase
|
||||
public function run(?PeriodicLoop $loop)
|
||||
{
|
||||
$this->loop = $loop;
|
||||
delay(0.001);
|
||||
$this->runCount++;
|
||||
return $this->retValue;
|
||||
}
|
||||
@ -142,13 +138,13 @@ class PeriodicTest extends AsyncTestCase
|
||||
$this->assertEquals(0, $runCount);
|
||||
|
||||
$this->assertTrue($loop->start());
|
||||
delay(0.002);
|
||||
$this->fixtureStarted($loop);
|
||||
|
||||
$this->assertEquals($loop, $l);
|
||||
LoopTest::waitTick();
|
||||
|
||||
$this->assertEquals(1, $runCount);
|
||||
|
||||
$this->assertEquals($loop, $l);
|
||||
|
||||
delay(0.048);
|
||||
$this->fixtureStarted($loop);
|
||||
|
||||
@ -160,7 +156,7 @@ class PeriodicTest extends AsyncTestCase
|
||||
$this->assertEquals(2, $runCount);
|
||||
|
||||
$this->assertTrue($loop->resume());
|
||||
delay(0.002);
|
||||
LoopTest::waitTick();
|
||||
|
||||
$this->assertEquals(3, $runCount);
|
||||
|
||||
@ -170,7 +166,7 @@ class PeriodicTest extends AsyncTestCase
|
||||
$retValue = true;
|
||||
$this->assertTrue($loop->resume());
|
||||
}
|
||||
delay(0.002);
|
||||
LoopTest::waitTick();
|
||||
$this->assertEquals($stopSig ? 3 : 4, $runCount);
|
||||
|
||||
$this->assertFalse($loop->isRunning());
|
||||
|
Loading…
Reference in New Issue
Block a user