Skip to content
Snippets Groups Projects
Commit d732617b authored by Andreas Gohr's avatar Andreas Gohr
Browse files

new helper method waitForTick() in DokuWikiTest

Some of our tests require that at least one second has passed before
they can continue because our revisions depend on the Unix Timestamp.

Currently we use a sleep(1) for this. However this always waits a whole
second, even if the next second is already much closer or maybe already
here - especially when some processing has been done since the last
operation.

This new method waits for the next second by checking the time every
10th of a second. This might speed up some of our tests a bit.
parent 960532fd
No related branches found
No related tags found
No related merge requests found
......@@ -156,4 +156,26 @@ abstract class DokuWikiTest extends PHPUnit_Framework_TestCase {
return $this->getMock($originalClassName, $methods);
}
}
/**
* Waits until a new second has passed
*
* The very first call will return immeadiately, proceeding calls will return
* only after at least 1 second after the last call has passed.
*
* When passing $init=true it will not return immeadiately but use the current
* second as initialization. It might still return faster than a second.
*
* @param bool $init wait from now on, not from last time
* @return int new timestamp
*/
protected function waitForTick($init = false) {
static $last = 0;
if($init) $last = time();
while($last === $now = time()) {
usleep(100000); //recheck in a 10th of a second
}
$last = $now;
return $now;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment