コード例 #1
0
 /**
  * @dataProvider nonBlockingProvider
  *
  * @param $timeout
  * @param bool $wait
  * @param bool $finish
  * @param string $output
  * @param string $expectedOutput
  */
 public function testNonBlocking($timeout, $wait, $finish, $output, $expectedOutput)
 {
     $this->pid->shouldReceive("getPid")->withArgs([true])->andThrow("Silktide\\Teamster\\Exception\\PidException");
     $this->pid->shouldReceive("cleanPid")->once()->andReturn(true);
     // seems we need to use a real file and can't mock the filesystem
     $outFile = __DIR__ . "/output/output";
     $spec = $this->setupOutFile($outFile);
     // setup command
     $command = "php -r \"\\\$s = microtime(true); do {usleep({$timeout} / 4);} while (microtime(true) - \\\$s < {$timeout} / 1000000); echo '{$output}';\"";
     // do the test
     $runner = new ProcessRunner($this->pidFactory, $spec, "dud", 1, 5, 5);
     $runner->execute($command, false);
     $this->assertTrue($runner->isRunning($this->pid));
     if ($wait) {
         usleep($timeout * 2);
     }
     if ($finish) {
         $runner->finish($this->pid);
     }
     $this->assertFalse($runner->isRunning($this->pid));
     $this->assertEquals($expectedOutput, file_get_contents($outFile));
 }
コード例 #2
0
 public function testStart()
 {
     $this->input->shouldReceive("getArgument")->andReturn("start");
     $pid = getmypid();
     $this->pid->shouldReceive("getPid")->andReturn($pid);
     $poolCommand = "pool:command";
     // test when pool is already running
     $command = new PoolControlCommand($this->runnerFactory, $this->pidFactory, "pool.pid", $poolCommand);
     try {
         $command->execute($this->input, $this->output);
         $this->fail("Should not be able to start a pool when one is already running");
     } catch (ProcessException $e) {
     }
     // test when pool is stopped
     $noPidFile = "no.pid";
     $noPid = \Mockery::mock("Silktide\\Teamster\\Pool\\Pid\\PidInterface")->shouldIgnoreMissing(true);
     $noPid->shouldReceive("getPid")->atLeast()->times(1)->andThrow("Silktide\\Teamster\\Exception\\PidException");
     $noPidFactory = \Mockery::mock("Silktide\\Teamster\\Pool\\Pid\\PidFactoryInterface");
     $noPidFactory->shouldReceive("create")->withArgs([$noPidFile])->once()->andReturn($noPid);
     $this->runner->shouldReceive("execute")->withArgs([$poolCommand, false])->once();
     $command = new PoolControlCommand($this->runnerFactory, $noPidFactory, $noPidFile, $poolCommand);
     $command->execute($this->input, $this->output);
 }