コード例 #1
0
 public function runTestProcess($arguments, $expectedExitCode = 0, $timeout = 5)
 {
     $command = __DIR__ . '/../../../../bin/phpunit-parallel ' . $arguments;
     $loop = Factory::create();
     $p = new Process($command);
     $p->start($loop);
     $stdout = '';
     $stderr = '';
     $timer = $loop->addTimer($timeout, function () use($arguments, $p, $stdout, $stderr) {
         $p->terminate(SIGKILL);
         $this->fail("running phpunit-parallel with '{$arguments}' did not complete in time\nstdout: {$stdout}\nstderr: {$stderr}\n");
     });
     $p->stdout->on('data', function ($data) use(&$stdout) {
         $stdout .= $data;
     });
     $p->stderr->on('data', function ($data) use(&$stderr) {
         $stderr .= $data;
     });
     $p->on('exit', function () use($timer) {
         $timer->cancel();
     });
     $loop->run();
     if ($p->getExitCode() !== $expectedExitCode) {
         $this->fail("Process exited with code {$p->getExitCode()}, expected {$expectedExitCode}\nstdout: {$stdout}\nstderr: {$stderr}\n");
     }
     return [$stdout, $stderr];
 }
コード例 #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $arguments = $this->getCommandArguments($input);
     $builder = $this->getEnvironmentHelper()->getProcessBuilder($arguments);
     $command = $builder->getProcess()->getCommandLine();
     $loop = Factory::create();
     $process = new Process($command, $this->getEnvironmentHelper()->getCwd());
     $port = (int) $input->getOption('port');
     $server = $this->initializeServer($loop, $port);
     $started = false;
     $this->addEnvironmentInfo($port, $command);
     $loop->addPeriodicTimer(self::LOOP_TIMER_PERIOD, function (Timer $timer) use($output, $process, $server, &$started) {
         $clients = $server->getConnections();
         if (true === $started && false === $process->isRunning()) {
             exit($process->getExitCode());
         }
         if ($clients->count()) {
             if (!$process->isRunning()) {
                 $process->start($timer->getLoop());
                 $started = true;
                 $this->broadcastToClients($clients);
             }
             $callable = function ($output) use($clients) {
                 $this->buffer .= $output;
                 $this->broadcastToClients($clients);
             };
             $process->stdin->on('data', $callable);
             $process->stdout->on('data', $callable);
             $process->stderr->on('data', $callable);
         }
     });
     $server->bind();
     $loop->run();
 }
コード例 #3
0
 public function testTerminateWithStopAndContinueSignalsUsingEventLoop()
 {
     if (defined('PHP_WINDOWS_VERSION_BUILD')) {
         $this->markTestSkipped('Windows does not report signals via proc_get_status()');
     }
     if (!defined('SIGSTOP') && !defined('SIGCONT')) {
         $this->markTestSkipped('SIGSTOP and/or SIGCONT is not defined');
     }
     $loop = $this->createloop();
     $process = new Process('sleep 1; exit 0');
     $called = false;
     $exitCode = 'initial';
     $termSignal = 'initial';
     $process->on('exit', function () use(&$called, &$exitCode, &$termSignal) {
         $called = true;
         $exitCode = func_get_arg(0);
         $termSignal = func_get_arg(1);
     });
     $loop->addTimer(0.001, function (Timer $timer) use($process) {
         $process->start($timer->getLoop());
         $process->terminate(SIGSTOP);
         $this->assertSoon(function () use($process) {
             $this->assertTrue($process->isStopped());
             $this->assertTrue($process->isRunning());
             $this->assertEquals(SIGSTOP, $process->getStopSignal());
         });
         $process->terminate(SIGCONT);
         $this->assertSoon(function () use($process) {
             $this->assertFalse($process->isStopped());
             $this->assertEquals(SIGSTOP, $process->getStopSignal());
         });
     });
     $loop->run();
     $this->assertTrue($called);
     $this->assertSame(0, $exitCode);
     $this->assertNull($termSignal);
     $this->assertFalse($process->isRunning());
     $this->assertSame(0, $process->getExitCode());
     $this->assertNull($process->getTermSignal());
     $this->assertFalse($process->isTerminated());
 }