Skip to content

Commit

Permalink
Stabilize test case timing
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorial1024 committed Jan 5, 2025
1 parent 4b44780 commit f0de38d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tests/AsyncTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ public function testAsyncTimeout()
$task = new AsyncTask($timeoutTask);
$task->withTimeLimit(1)->start();
// we wait for it to timeout
$this->sleep(2);
$this->sleep(0.5);
$this->sleep(0.5);
$this->sleep(0.5);
// should have timed out
$this->assertFileExists($textFilePath, "The async task probably did not trigger its timeout handler because its timeout output file is not found.");
$this->assertStringEqualsFile($textFilePath, $message);
Expand Down
9 changes: 6 additions & 3 deletions tests/Tasks/TestTimeoutNormalTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ public function __construct(
public function execute(): void
{
// we have to sleep a bit to trigger the timeout
// the test has a timeout of 1s, so we try to sleep for 1.5s
sleep(1);
usleep(500000);
// the test has a timeout of 1s, so we try to sleep for slightly longer than 1 seconds
// this is currently 1.2 seconds
usleep(300000);
usleep(300000);
usleep(300000);
usleep(300000);
}

public function handleTimeout(): void
Expand Down

0 comments on commit f0de38d

Please sign in to comment.