From 4a38bcfe2c3a2d0ade6694177066420962d80a61 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 3 Mar 2016 18:50:54 +0100 Subject: [PATCH 1/5] Remove tick declaration This should only be declared by the entry script otherwise control is lost on the tick interval --- src/Alchemy/TaskManager/Job/AbstractJob.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Alchemy/TaskManager/Job/AbstractJob.php b/src/Alchemy/TaskManager/Job/AbstractJob.php index 8b2b5c7..233902a 100644 --- a/src/Alchemy/TaskManager/Job/AbstractJob.php +++ b/src/Alchemy/TaskManager/Job/AbstractJob.php @@ -123,7 +123,6 @@ public function getStatus() */ final public function run(JobDataInterface $data = null, $callback = null) { - declare(ticks=1); $data = $data ?: new NullJobData(); $this->dispatcher->dispatch(JobEvents::START, new JobEvent($this, $data)); $this->setup($data); @@ -150,7 +149,6 @@ final public function run(JobDataInterface $data = null, $callback = null) */ final public function singleRun(JobDataInterface $data = null, $callback = null) { - declare(ticks=1); $data = $data ?: new NullJobData(); $this->dispatcher->dispatch(JobEvents::START, new JobEvent($this, $data)); $this->setup($data); From 27aba6cf3720f0c073cd1c24e51b5885753fe5d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Burnichon?= Date: Fri, 11 Mar 2016 10:54:18 +0100 Subject: [PATCH 2/5] Refactor AbstractJobTest to add declare ticks --- .../Test/TaskManager/Job/AbstractJobTest.php | 137 +++++++++--------- 1 file changed, 69 insertions(+), 68 deletions(-) diff --git a/tests/Alchemy/Test/TaskManager/Job/AbstractJobTest.php b/tests/Alchemy/Test/TaskManager/Job/AbstractJobTest.php index 829e8ec..f668950 100644 --- a/tests/Alchemy/Test/TaskManager/Job/AbstractJobTest.php +++ b/tests/Alchemy/Test/TaskManager/Job/AbstractJobTest.php @@ -34,26 +34,7 @@ public function setUp() private function getPauseScript() { - return 'run(); - '; + return $this->createScript('', array(), '', '2'); } public function testCustomEventsAreWelcomed() @@ -91,58 +72,28 @@ public function testStopDispatchAnEventOnFirstCall() private function getPauseAndLoopScript() { - return 'run(); - '; + return $this->createScript('echo "loop\\n";' . PHP_EOL); } private function getEventsScript($throwException) { - return 'addSubscriber(new Alchemy\TaskManager\Event\JobSubscriber\StopSignalSubscriber(Neutron\SignalHandler\SignalHandler::getInstance())); - $job->addListener(JobEvents::START, function () { echo "job-start\n"; }); - $job->addListener(JobEvents::TICK, function () { echo "job-tick\n"; }); - $job->addListener(JobEvents::STOP, function () { echo "job-stop\n"; }); - $job->addListener(JobEvents::EXCEPTION, function () { echo "job-exception\n"; }); - $job->run(); - '; + $body = $throwException ? 'throw new \Exception("failure");' . PHP_EOL : ''; + $additionalUses = array( + 'Alchemy\TaskManager\Event\JobSubscriber\StopSignalSubscriber', + 'Alchemy\TaskManager\Event\JobEvents', + 'Neutron\SignalHandler\SignalHandler', + ); + + $jobInitializer = <<addSubscriber(new StopSignalSubscriber(SignalHandler::getInstance())); +\$job->addListener(JobEvents::START, function () { echo "job-start\\n"; }); +\$job->addListener(JobEvents::TICK, function () { echo "job-tick\\n"; }); +\$job->addListener(JobEvents::STOP, function () { echo "job-stop\\n"; }); +\$job->addListener(JobEvents::EXCEPTION, function () { echo "job-exception\\n"; }); + +EOS; + + return $this->createScript($body, $additionalUses, $jobInitializer); } public function testPauseDoesAPause() @@ -169,6 +120,7 @@ public function testEvents() $process->stop(); $this->assertFalse($process->isRunning()); $data = array_filter(explode("\n", $process->getOutput())); + $this->assertGreaterThanOrEqual(3, count($data), 'Expected more events'); $this->assertSame(JobEvents::START, $data[0]); $this->assertSame(JobEvents::TICK, $data[1]); $this->assertContains(JobEvents::STOP, $data); @@ -321,6 +273,55 @@ public function testJobCanBeRestartedAfterAFailure() $this->setExpectedException('Alchemy\Test\TaskManager\Job\JobFailureException', 'Total failure.'); $job->run(); } + + /** + * @param string $doRunBody + * @param string[] $additionalUses + * @param string $jobInitializer + * @param string $pauseDuration + * @return string + */ + private function createScript($doRunBody = '', array $additionalUses = array(), $jobInitializer = '', $pauseDuration = '0.1') + { + $path = realpath(__DIR__ . '/../../../../../vendor/autoload.php'); + + $createUseClosure = function ($useClause) { + return sprintf("use %s;\n", $useClause); + }; + + $additionalUses[] = 'Alchemy\TaskManager\Job\JobDataInterface'; + $additionalUses = array_unique($additionalUses); + sort($additionalUses); + + $useClauses = implode('', array_map($createUseClosure, $additionalUses)); + + return <<run(); + +EOS; + } } class JobTest extends AbstractJob From 0a27cd0a7e7322d0609426d14f81be5abc456e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Burnichon?= Date: Fri, 11 Mar 2016 12:10:14 +0100 Subject: [PATCH 3/5] Add ticks declaration to tests/bootstrap.php --- tests/bootstrap.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 74a03df..00150aa 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,7 @@ add('Alchemy\Test', __DIR__); $loader->add('Alchemy\Functional', __DIR__); From 9a4ca06d5d7e152d7fb4e4adad1c940fd2f93916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Burnichon?= Date: Fri, 11 Mar 2016 12:11:40 +0100 Subject: [PATCH 4/5] Remove prefer-source as not needed anymore --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b35462b..953c6a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ before_script: - phpenv config-rm xdebug.ini - echo "extension=zmq.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` - composer self-update - - composer install --prefer-source + - composer install script: - vendor/bin/phpunit -c phpunit.xml.dist From 5e4d6e65204006e8f09d91cf4150fdaf098f6df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Burnichon?= Date: Fri, 11 Mar 2016 12:33:36 +0100 Subject: [PATCH 5/5] Add composer to cache --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 953c6a8..febdc31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ language: php sudo: false +cache: + directories: + - $HOME/.composer + php: - '5.3' - '5.4'