@@ -258,4 +258,29 @@ public function testAsyncTaskNormalStatus()
258258 $ this ->assertFalse ($ preStatus ->isRunning (), "Stopped tasks should always report \"task stopped \". " );
259259 $ this ->assertTrue ($ liveStatus ->isRunning (), "Recently-started task does not report \"task running \". " );
260260 }
261+
262+ public function testAsyncTaskStatusWithTimeLimit ()
263+ {
264+ // test that the task status reading is correct, even if we are using a time limit
265+ $ taskID = "timeoutTestingTask " ;
266+ $ task = new AsyncTask (new SleepingAsyncTask (), taskID: $ taskID );
267+
268+ // we haven't started yet, so this should say false
269+ $ preStatus = new AsyncTaskStatus ($ taskID );
270+ $ this ->assertFalse ($ preStatus ->isRunning ());
271+ // note: since it detects false, it will always continue to say false
272+ $ this ->assertFalse ($ preStatus ->isRunning ());
273+
274+ // now we start running the task
275+ $ liveStatus = $ task ->withTimeLimit (4 )->start ();
276+
277+ // try to sleep a bit, to stabilize the test case
278+ $ this ->sleep (0.1 );
279+
280+ // the task is to sleep for some time, and then exit.
281+ // note: since checking the task statuses take some time, we cannot confirm the actual elapsed time of our tests,
282+ // and so "task ended" case is not testable
283+ $ this ->assertFalse ($ preStatus ->isRunning (), "Stopped tasks should always report \"task stopped \". " );
284+ $ this ->assertTrue ($ liveStatus ->isRunning (), "Recently-started task does not report \"task running \". " );
285+ }
261286}
0 commit comments