From 2ae54583f040587e1e72853ec39dcf6f0ebf9a18 Mon Sep 17 00:00:00 2001 From: David Abdemoulaie Date: Tue, 14 Dec 2010 23:35:18 -0600 Subject: [PATCH] Fixes unit test reliability - redis-server is killed only from parent process, not from a worker - sleeps for half a second after starting server --- test/Resque/Tests/bootstrap.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/Resque/Tests/bootstrap.php b/test/Resque/Tests/bootstrap.php index e21707c..c7ded09 100644 --- a/test/Resque/Tests/bootstrap.php +++ b/test/Resque/Tests/bootstrap.php @@ -30,6 +30,7 @@ if($returnVar != 0) { } exec('cd ' . TEST_MISC . '; redis-server ' . REDIS_CONF, $output, $returnVar); +usleep(500000); if($returnVar != 0) { echo "Cannot start redis-server.\n"; exit(1); @@ -46,8 +47,11 @@ if(!preg_match('#^\s*port\s+([0-9]+)#m', $config, $matches)) { Resque::setBackend('localhost:' . $matches[1]); // Shutdown -function killRedis() +function killRedis($pid) { + if (getmypid() !== $pid) { + return; // don't kill from a forked worker + } $config = file_get_contents(REDIS_CONF); if(!preg_match('#^\s*pidfile\s+([^\s]+)#m', $config, $matches)) { return; @@ -76,7 +80,7 @@ function killRedis() unlink($filename); } } -register_shutdown_function('killRedis'); +register_shutdown_function('killRedis', getmypid()); if(function_exists('pcntl_signal')) { // Override INT and TERM signals, so they do a clean shutdown and also