|
6 | 6 | use RuntimeException; |
7 | 7 | use Vectorial1024\LaravelProcessAsync\AsyncTask; |
8 | 8 | use Vectorial1024\LaravelProcessAsync\Tests\Tasks\DummyAsyncTask; |
| 9 | +use Vectorial1024\LaravelProcessAsync\Tests\Tasks\TestTimeoutENoticeTask; |
| 10 | +use Vectorial1024\LaravelProcessAsync\Tests\Tasks\TestTimeoutErrorTask; |
| 11 | +use Vectorial1024\LaravelProcessAsync\Tests\Tasks\TestTimeoutNoOpTask; |
9 | 12 | use Vectorial1024\LaravelProcessAsync\Tests\Tasks\TestTimeoutNormalTask; |
10 | 13 |
|
11 | 14 | class AsyncTaskTest extends BaseTestCase |
@@ -145,4 +148,49 @@ public function testAsyncTimeout() |
145 | 148 | $this->assertStringEqualsFile($textFilePath, $message); |
146 | 149 | $this->assertNoNohupFile(); |
147 | 150 | } |
| 151 | + |
| 152 | + public function testAsyncTimeoutIgnoreErrors() |
| 153 | + { |
| 154 | + // test that the async timeout handler is not triggered due to other fatal errors |
| 155 | + $message = "timeout occured"; |
| 156 | + $textFilePath = $this->getStoragePath("testAsyncTimeoutIgnoreErrors.txt"); |
| 157 | + $timeoutTask = new TestTimeoutErrorTask($message, $textFilePath); |
| 158 | + $task = new AsyncTask($timeoutTask); |
| 159 | + $task->withTimeLimit(1)->start(); |
| 160 | + // we wait for it to timeout |
| 161 | + $this->sleep(1); |
| 162 | + // should have timed out |
| 163 | + $this->assertFileDoesNotExist($textFilePath, "The async task timeout handler was inappropriately triggered (PHP fatal errors should not trigger timeouts)."); |
| 164 | + $this->assertNoNohupFile(); |
| 165 | + } |
| 166 | + |
| 167 | + public function testAsyncTimeoutIgnoreNoProblem() |
| 168 | + { |
| 169 | + // test that the async timeout handler is not triggered when nothing happened |
| 170 | + $message = "timeout occured"; |
| 171 | + $textFilePath = $this->getStoragePath("testAsyncTimeoutIgnoreNoProblem.txt"); |
| 172 | + $timeoutTask = new TestTimeoutNoOpTask($message, $textFilePath); |
| 173 | + $task = new AsyncTask($timeoutTask); |
| 174 | + $task->withTimeLimit(1)->start(); |
| 175 | + // we wait for it to timeout |
| 176 | + $this->sleep(1); |
| 177 | + // should have timed out |
| 178 | + $this->assertFileDoesNotExist($textFilePath, "The async task timeout handler was inappropriately triggered (finishing a task before the time limit should not trigger timeouts)."); |
| 179 | + $this->assertNoNohupFile(); |
| 180 | + } |
| 181 | + |
| 182 | + public function testAsyncTimeoutIgnoreENotice() |
| 183 | + { |
| 184 | + // test that the async timeout handler is not triggered when there is an E_NOTICE error |
| 185 | + $message = "timeout occured"; |
| 186 | + $textFilePath = $this->getStoragePath("testAsyncTimeoutIgnoreENotice.txt"); |
| 187 | + $timeoutTask = new TestTimeoutENoticeTask($message, $textFilePath); |
| 188 | + $task = new AsyncTask($timeoutTask); |
| 189 | + $task->withTimeLimit(1)->start(); |
| 190 | + // we wait for it to timeout |
| 191 | + $this->sleep(1); |
| 192 | + // should have timed out |
| 193 | + $this->assertFileDoesNotExist($textFilePath, "The async task timeout handler was inappropriately triggered (E_NOTICE should not trigger timeouts)."); |
| 194 | + $this->assertNoNohupFile(); |
| 195 | + } |
148 | 196 | } |
0 commit comments