Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 48
Windows test suite compatibility#13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -68,22 +68,29 @@ public function testGetTermSignalWhenRunning($process) | ||
| public function testProcessWithDefaultCwdAndEnv() | ||
| { | ||
| $cmd = $this->getPhpBinary() . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL, count($_SERVER), PHP_EOL;'); | ||
| $cmd = $this->getPhpCommandLine('echo getcwd(), PHP_EOL, count($_SERVER), PHP_EOL;'); | ||
| $loop = $this->createLoop(); | ||
| $process = new Process($cmd); | ||
| $output = ''; | ||
| $error = ''; | ||
| $loop->addTimer(0.001, function(Timer $timer) use ($process, &$output) { | ||
| $loop->addTimer(0.001, function(Timer $timer) use ($process, &$output, &$error) { | ||
| $process->start($timer->getLoop()); | ||
| $process->stdout->on('data', function () use (&$output) { | ||
| $output .= func_get_arg(0); | ||
| $process->stdout->on('data', function ($data) use (&$output) { | ||
| $output .= $data; | ||
| }); | ||
| $process->stderr->on('data', function ($data) use (&$error) { | ||
| $error .= $data; | ||
| }); | ||
| }); | ||
| $loop->run(); | ||
| $this->assertEmpty($error); | ||
| $this->assertNotEmpty($output); | ||
| list($cwd, $envCount) = explode(PHP_EOL, $output); | ||
| /* Child process should inherit the same current working directory and | ||
| @@ -96,10 +103,11 @@ public function testProcessWithDefaultCwdAndEnv() | ||
| public function testProcessWithCwd() | ||
| { | ||
| $cmd = $this->getPhpBinary() . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL;'); | ||
| $cmd = $this->getPhpCommandLine('echo getcwd(), PHP_EOL;'); | ||
| $cwd = defined('PHP_WINDOWS_VERSION_BUILD') ? 'C:\\' : '/'; | ||
| $loop = $this->createLoop(); | ||
| $process = new Process($cmd, '/'); | ||
| $process = new Process($cmd, $cwd); | ||
| $output = ''; | ||
| @@ -112,7 +120,7 @@ public function testProcessWithCwd() | ||
| $loop->run(); | ||
| $this->assertSame('/' . PHP_EOL, $output); | ||
| $this->assertSame($cwd . PHP_EOL, $output); | ||
| } | ||
| public function testProcessWithEnv() | ||
| @@ -121,7 +129,13 @@ public function testProcessWithEnv() | ||
| $this->markTestSkipped('Cannot execute PHP processes with custom environments on Travis CI.'); | ||
| } | ||
| $cmd = $this->getPhpBinary() . ' -r ' . escapeshellarg('echo getenv("foo"), PHP_EOL;'); | ||
| $cmd = $this->getPhpCommandLine('echo getenv("foo"), PHP_EOL;'); | ||
| if (defined('PHP_WINDOWS_VERSION_BUILD')) { | ||
| // Windows madness! escapeshellarg seems to completely remove double quotes in Windows! | ||
| // We need to use simple quotes in our PHP code! | ||
| $cmd = $this->getPhpCommandLine('echo getenv(\'foo\'), PHP_EOL;'); | ||
| } | ||
| $loop = $this->createLoop(); | ||
| $process = new Process($cmd, null, array('foo' => 'bar')); | ||
| @@ -173,6 +187,10 @@ public function testStartAndAllowProcessToExitSuccessfullyUsingEventLoop() | ||
| public function testStartInvalidProcess() | ||
| { | ||
| if (defined('PHP_WINDOWS_VERSION_BUILD')) { | ||
| $this->markTestSkipped('Windows does not have an executable flag.'); | ||
| } | ||
| $cmd = tempnam(sys_get_temp_dir(), 'react'); | ||
| $loop = $this->createLoop(); | ||
| @@ -298,6 +316,49 @@ public function testTerminateWithStopAndContinueSignalsUsingEventLoop() | ||
| $this->assertFalse($process->isTerminated()); | ||
| } | ||
| /** | ||
| * @dataProvider provideOutputSizeAndExpectedMaxDuration | ||
| */ | ||
| public function testProcessWithFixedOutputSize($size, $expectedMaxDuration = 5) | ||
| { | ||
| // Note: very strange behaviour of Windows (PHP 5.5.6): | ||
| // on a 1000 long string, Windows succeeds. | ||
| // on a 10000 long string, Windows fails to output anything. | ||
| // On a 100000 long string, it takes a lot of time but succeeds. | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. | ||
| $cmd = $this->getPhpCommandLine(sprintf('echo str_repeat("o", %d), PHP_EOL;', $size)); | ||
| $loop = $this->createLoop(); | ||
| $process = new Process($cmd); | ||
| $output = ''; | ||
| $loop->addTimer(0.001, function(Timer $timer) use ($process, &$output) { | ||
| $process->start($timer->getLoop()); | ||
| $process->stdout->on('data', function () use (&$output) { | ||
| $output .= func_get_arg(0); | ||
| }); | ||
| }); | ||
| $startTime = microtime(true); | ||
| $loop->run(); | ||
| $endTime = microtime(true); | ||
| $expectedOutput = str_repeat('o', $size) . PHP_EOL; | ||
| $this->assertEquals(strlen($expectedOutput), strlen($output)); | ||
| $this->assertSame($expectedOutput, $output); | ||
| $this->assertLessThanOrEqual($expectedMaxDuration, $endTime - $startTime, "Process took longer than expected."); | ||
| } | ||
| public function provideOutputSizeAndExpectedMaxDuration() | ||
| { | ||
| return [ | ||
| [1000, 5], | ||
| [10000, 5], | ||
| [100000, 5], | ||
| ]; | ||
| } | ||
| /** | ||
| * Execute a callback at regular intervals until it returns successfully or | ||
| * a timeout is reached. | ||
| @@ -333,4 +394,19 @@ private function getPhpBinary() | ||
| return $runtime->getBinary(); | ||
| } | ||
| private function getPhpCommandLine($phpCode) | ||
| { | ||
| /* The following is a suitable workaround for Windows given some | ||
| * escapeshellarg() incompatibilies in older PHP versions and knowledge | ||
| * that we're only escaping echo statements destined for "php -r". | ||
| * | ||
| * See: http://php.net/manual/en/function.escapeshellarg.php#114873 | ||
| */ | ||
| $phpCode = defined('PHP_WINDOWS_VERSION_BUILD') | ||
| ? '"' . addcslashes($phpCode, '\\"') . '"' | ||
| : escapeshellarg($phpCode); | ||
| return $this->getPhpBinary() . ' -r ' . $phpCode; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@moufmouf: Why was the stderr check only added to this test case? Was there a case where it failed on Windows and you caught some output here?