/** * Track the time it took a worker to complete. * * @param Worker $worker * @return void */ public function onWorkerCompleted(Worker $worker) { $info = $worker->getJobInfo(); $this->times[$info->file] = $info->end - $info->start; $data = $this->suites[$info->file]; if ($data) { $this->writeTestReport($this->suites[$info->file]); } }
expect($error)->to->not->satisfy('is_resource'); expect($process)->to->not->satisfy('is_resource'); }); it('should stop a running worker', function () { $this->worker->run('/path/to/test.php'); $this->worker->close(); expect($this->worker->isRunning())->to->be->false; expect($this->worker->isStarted())->to->be->false; }); }); describe('->free()', function () { it('should make the worker stop running', function () { $this->worker->run('/path/to/test.php'); $this->worker->free(); expect($this->worker->isRunning())->to->be->false; }); }); describe('->isRunning()', function () { it('should set the running status to false if an open proc has exited', function () { $worker = new Worker('php -v', $this->emitter, new ProcOpen()); $worker->start(); $start = microtime(true); while ($worker->isRunning()) { $now = microtime(true) - $start; if ($now > 2) { throw new Exception("Timeout exceeded 2 second limit"); } } }); }); });
}); }); context('when test.failed event is emitted', function () { beforeEach(function () { $this->emitter->emit('test.failed', [$this->test, $this->exception]); }); it('should store the test and exception on the suite entry', function () { $suites = $this->reporter->getSuites(); $entry = $suites[__FILE__][0]; expect($entry['test'])->to->equal($this->test); expect($entry['exception'])->to->equal($this->exception); }); }); context('when a peridot.concurrency.worker.completed event is emitted', function () { it('should associated elapsed time from the worker', function () { $worker = new Worker('/path/to/executable.php', $this->emitter, new TmpfileOpen()); $worker->run(__FILE__); $worker->getJobInfo()->end = microtime(true); $this->emitter->emit('test.passed', [$this->test]); $this->emitter->emit('peridot.concurrency.worker.completed', [$worker]); $info = $worker->getJobInfo(); $time = $this->reporter->getTimeFor(__FILE__); expect($time)->to->equal($info->end - $info->start); }); }); context('when a peridot.concurrency.runner.end event is emitted', function () { it('should output a run time', function () { $this->emitter->emit('peridot.concurrency.runner.end', [0, []]); $output = $this->output->fetch(); expect($output)->to->have->string('Run time: 0 ms'); });