/** * Read a suite path on the environment's read stream and execute * them against a standard Peridot runner. * * @param Context $context * @param Environment $environment * @param Message $message * @return void */ public function loop(Context $context, Environment $environment, Message $message) { while (true) { $input = fgets($environment->getReadStream()); list($token, $path) = $this->getTestInfo($input); $context->setFile($path); putenv("PERIDOT_TEST_TOKEN={$token}"); require $path; $runner = new Runner($context->getCurrentSuite(), $environment->getConfiguration(), $environment->getEventEmitter()); $runner->run(new TestResult($environment->getEventEmitter())); $message->end(); $context->clear(); } }
/** * Remove the worker that erred and replace it. * * @param $error * @param Message $message * @return void */ public function onError($error, Message $message) { $worker = $this->getWorkerForStream($message->getResource()); if ($worker === null) { return; } $this->eventEmitter->emit('peridot.concurrency.worker.error', [$error, $worker]); $this->detach($worker); $this->broker->removeMessage($message); $worker = new Worker($this->command, $this->eventEmitter, $this->resourceOpen); $this->attach($worker); }
/** * If the given message owns the passed in resource, then * read data on that message. * * @param Message $message * @param resource $resource * @return void */ protected function readResource(Message $message, $resource) { if ($message->getResource() === $resource) { $message->receive(); } }
$stream = $this->message->getResource(); fseek($stream, 0); $content = fread($stream, 128); expect($content)->to->equal("last\nTERMINATE\n"); }); it('should write only a terminate single if content is omitted', function () { $this->message->end(); $stream = $this->message->getResource(); fseek($stream, 0); $content = fread($stream, 128); expect($content)->to->equal("TERMINATE\n"); }); }); describe('->getResource()', function () { it('should return the underlying resource', function () { $message = new Message($this->resource); expect($message->getResource())->to->equal($this->resource); }); }); describe('string packer accessors', function () { it('should allow access to the message string packer', function () { $packer = new StringPacker(); $this->message->setStringPacker($packer); expect($this->message->getStringPacker())->to->equal($packer); }); }); describe('broker accessors', function () { it('should allow access to the message broker', function () { $broker = new MessageBroker(); $this->message->setMessageBroker($broker); expect($this->message->getMessageBroker())->to->equal($broker);
/** * Write the test message. If content is supplied it will * be used instead of the internal serialized data structure. * * @param string $content * @return void */ public function write($content = '') { if (!$content) { $content = json_encode($this->data); } parent::write($content); }