MDL-55944 testing: Reduce sleep usage.

Remove sleep() and replace with waiting for a second to roll over,
this results in a simpler call the guarantee time() has moved forward
This commit is contained in:
Russell Smith
2016-09-14 10:26:14 +10:00
parent b022c2cd1c
commit 85efc6975a
6 changed files with 19 additions and 6 deletions
+13
View File
@@ -607,4 +607,17 @@ abstract class advanced_testcase extends base_testcase {
}
}
}
/**
* Wait for a second to roll over, ensures future calls to time() return a different result.
*
* This is implemented instead of sleep() as we do not need to wait a full second. In some cases
* due to calls we may wait more than sleep() would have, on average it will be less.
*/
public function waitForSecond() {
$starttime = time();
while (time() == $starttime) {
usleep(50000);
}
}
}