Commit 8c6ee08d authored by Dries's avatar Dries
Browse files

Patch #84008 by deviantintegral, plumbley, lilou, lambic: fixed timer_read()...

Patch #84008 by deviantintegral, plumbley, lilou, lambic: fixed timer_read() returns NULL (no value) after timer_stop(). Added timer tests.
parent 2dc3c05a
...@@ -248,6 +248,7 @@ function timer_read($name) { ...@@ -248,6 +248,7 @@ function timer_read($name) {
} }
return $diff; return $diff;
} }
return $timers[$name]['time'];
} }
/** /**
...@@ -262,7 +263,12 @@ function timer_read($name) { ...@@ -262,7 +263,12 @@ function timer_read($name) {
function timer_stop($name) { function timer_stop($name) {
global $timers; global $timers;
$timers[$name]['time'] = timer_read($name); if (isset($timers[$name]['time'])) {
$timers[$name]['time'] += timer_read($name);
}
else {
$timers[$name]['time'] = timer_read($name);
}
unset($timers[$name]['start']); unset($timers[$name]['start']);
return $timers[$name]; return $timers[$name];
......
...@@ -311,3 +311,35 @@ class BootstrapGetFilenameTestCase extends DrupalUnitTestCase { ...@@ -311,3 +311,35 @@ class BootstrapGetFilenameTestCase extends DrupalUnitTestCase {
$this->assertIdentical(drupal_get_filename('profile', 'default'), 'profiles/default/default.profile', t('Retrieve install profile location.')); $this->assertIdentical(drupal_get_filename('profile', 'default'), 'profiles/default/default.profile', t('Retrieve install profile location.'));
} }
} }
class BootstrapTimerTestCase extends DrupalUnitTestCase {
public static function getInfo() {
return array(
'name' => 'Timer test',
'description' => 'Test that timer_read() works both when a timer is running and when a timer is stopped.',
'group' => 'Bootstrap',
);
}
/**
* Test timer_read() to ensure it properly accumulates time when the timer
* started and stopped multiple times.
* @return
*/
function testTimer() {
timer_start('test');
sleep(1);
$this->assertTrue(timer_read('test') >= 1000, t('Timer measured 1 second of sleeping while running.'));
sleep(1);
timer_stop('test');
$this->assertTrue(timer_read('test') >= 2000, t('Timer measured 2 seconds of sleeping after being stopped.'));
timer_start('test');
sleep(1);
$this->assertTrue(timer_read('test') >= 3000, t('Timer measured 3 seconds of sleeping after being restarted.'));
sleep(1);
$timer = timer_stop('test');
$this->assertTrue(timer_read('test') >= 4000, t('Timer measured 4 seconds of sleeping after being stopped for a second time.'));
$this->assertEqual($timer['count'], 2, t('Timer counted 2 instances of being started.'));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment