From a4b1fa64fa217b4b142cd6a9eacfd6e468551cdc Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Wed, 6 Dec 2017 20:41:07 -0600 Subject: [PATCH] Update tests Improved some tests and (hopefully) fixed a timing issue on windows in kill test. --- test/ProcessTest.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/ProcessTest.php b/test/ProcessTest.php index 22b458a..fddcc3b 100644 --- a/test/ProcessTest.php +++ b/test/ProcessTest.php @@ -2,6 +2,7 @@ namespace Amp\Process\Test; +use Amp\Delayed; use Amp\Loop; use Amp\Process\Process; use Amp\Process\ProcessInputStream; @@ -56,7 +57,7 @@ class ProcessTest extends TestCase { $process->start(); $this->assertInternalType('int', yield $process->getPid()); - yield $process->join(); + $this->assertSame(0, yield $process->join()); }); } @@ -70,7 +71,7 @@ class ProcessTest extends TestCase { $process->start(); $process->signal(0); $this->assertInstanceOf(Promise::class, $process->getPid()); - yield $process->join(); + $this->assertSame(0, yield $process->join()); }); } @@ -184,10 +185,26 @@ class ProcessTest extends TestCase { * @expectedException \Amp\Process\ProcessException * @expectedExceptionMessage The process was killed */ - public function testKillSignals() { + public function testKillImmediately() { Loop::run(function () { $process = new Process(self::CMD_PROCESS_SLOW); $process->start(); + $process->kill(); + yield $process->join(); + }); + } + + /** + * @expectedException \Amp\Process\ProcessException + * @expectedExceptionMessage The process was killed + */ + public function testKillThenReadStdout() { + Loop::run(function () { + $process = new Process(self::CMD_PROCESS_SLOW); + $process->start(); + + yield new Delayed(100); // Give process a chance to start, otherwise a different error is thrown. + $process->kill(); $this->assertNull(yield $process->getStdout()->read()); @@ -196,6 +213,7 @@ class ProcessTest extends TestCase { }); } + /** * @expectedException \Amp\Process\StatusError * @expectedExceptionMessage Process has not been started.