Skip to content

Commit c526ac3

Browse files
committed
Adjust test sleeping
1 parent bbe19e3 commit c526ac3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

tests/AsyncTaskTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testAsyncBasic()
8686
$task->start();
8787

8888
// sleep a bit to wait for the async
89-
sleep(1);
89+
$this->sleep(1.5);
9090

9191
$this->assertFileExists($testFileName, "The async task probably did not run because its output file cannot be found.");
9292
$this->assertStringEqualsFile($testFileName, $message);

tests/BaseTestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ protected function getStoragePath(string $fileName): string
3030
return dirname(__FILE__, 2) . "/storage/$fileName";
3131
}
3232

33+
/**
34+
* Sleeps for some time.
35+
* @param float $seconds The number of seconds.
36+
* @return void
37+
*/
38+
protected function sleep(float $seconds): void
39+
{
40+
$wholeSeconds = (int) $seconds;
41+
$fractionalSeconds = $seconds - $wholeSeconds;
42+
sleep($wholeSeconds);
43+
usleep($fractionalSeconds * 1000000);
44+
}
45+
3346
// ---
3447

3548
public function call($method, $uri, $parameters = [], $files = [], $server = [], $content = null, $changeHistory = true)

0 commit comments

Comments
 (0)