Skip to content

Commit d165daf

Browse files
committed
Add test
1 parent 1d5f9f8 commit d165daf

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/TaskHandlerTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Tests;
44

5+
use Carbon\Carbon;
56
use Firebase\JWT\JWT;
67
use Firebase\JWT\SignatureInvalidException;
78
use Google\Cloud\Tasks\V2\Attempt;
@@ -279,7 +280,70 @@ public function hasMaxRetryDuration() {
279280

280281
$this->cloudTasksClient->shouldNotHaveReceived('deleteTask');
281282
}
283+
}
284+
285+
/**
286+
* @test
287+
* @testWith [{"retryCount": 1, "shouldHaveFailed": false}]
288+
* [{"retryCount": 2, "shouldHaveFailed": false}]
289+
* [{"retryCount": 2, "travelSeconds": 29, "shouldHaveFailed": false}]
290+
* [{"retryCount": 2, "travelSeconds": 31, "shouldHaveFailed": true}]
291+
*/
292+
public function job_max_attempts_is_ignored_if_has_retry_until($example)
293+
{
294+
// Arrange
295+
$this->request->headers->add(['X-CloudTasks-TaskRetryCount' => $example['retryCount']]);
296+
297+
$now = Carbon::now()->getTimestamp();
298+
if (array_key_exists('travelSeconds', $example)) {
299+
Carbon::setTestNow(Carbon::now()->addSeconds($example['travelSeconds']));
300+
}
301+
302+
$this->cloudTasksClient->shouldReceive('getQueue')
303+
->byDefault()
304+
->andReturn(new class() {
305+
public function getRetryConfig() {
306+
return new class {
307+
public function getMaxAttempts() {
308+
return 3;
309+
}
310+
311+
public function hasMaxRetryDuration() {
312+
return true;
313+
}
282314

315+
public function getMaxRetryDuration() {
316+
return new class {
317+
public function getSeconds() {
318+
return 30;
319+
}
320+
};
321+
}
322+
};
323+
}
324+
});
325+
326+
$this->cloudTasksClient
327+
->shouldReceive('getTask')
328+
->byDefault()
329+
->andReturn(new class {
330+
public function getFirstAttempt() {
331+
return (new Attempt())
332+
->setDispatchTime(new Timestamp([
333+
'seconds' => time(),
334+
]));
335+
}
336+
});
337+
338+
rescue(function () {
339+
$this->handler->handle($this->failingJob());
340+
});
341+
342+
if ($example['shouldHaveFailed']) {
343+
$this->cloudTasksClient->shouldHaveReceived('deleteTask');
344+
} else {
345+
$this->cloudTasksClient->shouldNotHaveReceived('deleteTask');
346+
}
283347
}
284348

285349
private function simpleJob()

0 commit comments

Comments
 (0)