You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/AsyncTaskTest.php
+18Lines changed: 18 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -67,4 +67,22 @@ public function testAsyncBasic()
67
67
68
68
unlink($testFileName);
69
69
}
70
+
71
+
publicfunctiontestAsyncBackground()
72
+
{
73
+
// tests that the async really runs in the background: it should not block the main thread
74
+
// test by starting a long sleep task and check the elapsed time in the main process
75
+
// note: we cannot test the "nohup" part because we can't really kill phpunit and start it up again on demand
76
+
$sleepDuration = 2; // how many seconds
77
+
$task = newAsyncTask(function () use ($sleepDuration) {
78
+
// just sleep long is ok
79
+
sleep($sleepDuration);
80
+
});
81
+
// time it
82
+
$timeBefore = microtime(true);
83
+
$task->start();
84
+
$timeAfter = microtime(true);
85
+
$timeElapsed = $timeAfter - $timeBefore;
86
+
$this->assertLessThan($sleepDuration, $timeElapsed, "The async task probably did not start in the background because the time taken to start it was too long.");
0 commit comments