Skip to content

Commit

Permalink
Handle missing LARAVEL_START during test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorial1024 committed Dec 30, 2024
1 parent f4513c5 commit ae53283
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/AsyncTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function run(): void
{
// todo startup configs
// write down the LARAVEL_START constant value for future usage
$this->laravelStartVal = constant("LARAVEL_START");
$this->laravelStartVal = constant("LARAVEL_START") ?? null;

// install a timeout detector
// this single function checks all kinds of timeouts
Expand Down Expand Up @@ -257,10 +257,13 @@ protected function checkTaskTimeout(): void

// external killing; could be normal Unix timeout SIG_TERM or manual Windows taskkill
// Laravel Artisan very conveniently has a LARAVEL_START = microtime(true) to let us check time elapsed
$timeElapsed = microtime(true) - $this->laravelStartVal;
if ($timeElapsed > $this->timeLimit) {
// timeout!
$hasTimedOut = true;
if ($this->laravelStartVal !== null) {
// we know when we have started; this can be null when running some test cases
$timeElapsed = microtime(true) - $this->laravelStartVal;
if ($timeElapsed > $this->timeLimit) {
// timeout!
$hasTimedOut = true;
}
}

// runtime timeout triggers a PHP fatal error
Expand Down

0 comments on commit ae53283

Please sign in to comment.