Fixes unit test reliability

- redis-server is killed only from parent process, not from a worker
- sleeps for half a second after starting server
This commit is contained in:
David Abdemoulaie 2010-12-14 23:35:18 -06:00
parent 27758b47be
commit 2ae54583f0

View File

@ -30,6 +30,7 @@ if($returnVar != 0) {
} }
exec('cd ' . TEST_MISC . '; redis-server ' . REDIS_CONF, $output, $returnVar); exec('cd ' . TEST_MISC . '; redis-server ' . REDIS_CONF, $output, $returnVar);
usleep(500000);
if($returnVar != 0) { if($returnVar != 0) {
echo "Cannot start redis-server.\n"; echo "Cannot start redis-server.\n";
exit(1); exit(1);
@ -46,8 +47,11 @@ if(!preg_match('#^\s*port\s+([0-9]+)#m', $config, $matches)) {
Resque::setBackend('localhost:' . $matches[1]); Resque::setBackend('localhost:' . $matches[1]);
// Shutdown // Shutdown
function killRedis() function killRedis($pid)
{ {
if (getmypid() !== $pid) {
return; // don't kill from a forked worker
}
$config = file_get_contents(REDIS_CONF); $config = file_get_contents(REDIS_CONF);
if(!preg_match('#^\s*pidfile\s+([^\s]+)#m', $config, $matches)) { if(!preg_match('#^\s*pidfile\s+([^\s]+)#m', $config, $matches)) {
return; return;
@ -76,7 +80,7 @@ function killRedis()
unlink($filename); unlink($filename);
} }
} }
register_shutdown_function('killRedis'); register_shutdown_function('killRedis', getmypid());
if(function_exists('pcntl_signal')) { if(function_exists('pcntl_signal')) {
// Override INT and TERM signals, so they do a clean shutdown and also // Override INT and TERM signals, so they do a clean shutdown and also