@@ -56,23 +56,29 @@ protected function setUp(): void
5656
5757 // Ensure we don't fetch the Queue name and attempts each test...
5858 $ cloudTasksClient ->shouldReceive ('queueName ' )->andReturn ('my-queue ' );
59- $ cloudTasksClient ->shouldReceive ('getQueue ' )->andReturn (new class {
60- public function getRetryConfig () {
61- return new class {
62- public function getMaxAttempts () {
63- return 3 ;
64- }
65-
66- public function getMaxRetryDuration () {
67- return new class {
68- public function getSeconds () {
69- return 30 ;
70- }
71- };
72- }
73- };
74- }
75- });
59+ $ cloudTasksClient ->shouldReceive ('getQueue ' )
60+ ->byDefault ()
61+ ->andReturn (new class {
62+ public function getRetryConfig () {
63+ return new class {
64+ public function getMaxAttempts () {
65+ return 3 ;
66+ }
67+
68+ public function hasMaxRetryDuration () {
69+ return true ;
70+ }
71+
72+ public function getMaxRetryDuration () {
73+ return new class {
74+ public function getSeconds () {
75+ return 30 ;
76+ }
77+ };
78+ }
79+ };
80+ }
81+ });
7682 $ cloudTasksClient ->shouldReceive ('taskName ' )->andReturn ('FakeTaskName ' );
7783 $ cloudTasksClient ->shouldReceive ('getTask ' )->byDefault ()->andReturn (new class {
7884 public function getFirstAttempt () {
@@ -245,6 +251,37 @@ public function getFirstAttempt() {
245251 $ this ->cloudTasksClient ->shouldHaveReceived ('deleteTask ' )->once ();
246252 }
247253
254+ /** @test */
255+ public function test_unlimited_max_attempts ()
256+ {
257+ $ this ->cloudTasksClient ->shouldReceive ('getQueue ' )
258+ ->byDefault ()
259+ ->andReturn (new class {
260+ public function getRetryConfig () {
261+ return new class {
262+ public function getMaxAttempts () {
263+ return -1 ;
264+ }
265+
266+ public function hasMaxRetryDuration () {
267+ return false ;
268+ }
269+ };
270+ }
271+ });
272+
273+ for ($ i = 0 ; $ i < 50 ; $ i ++) {
274+ $ this ->request ->headers ->add (['X-CloudTasks-TaskRetryCount ' => $ i ]);
275+
276+ rescue (function () {
277+ $ this ->handler ->handle ($ this ->failingJob ());
278+ });
279+
280+ $ this ->cloudTasksClient ->shouldNotHaveReceived ('deleteTask ' );
281+ }
282+
283+ }
284+
248285 private function simpleJob ()
249286 {
250287 return json_decode (file_get_contents (__DIR__ . '/Support/test-job-payload.json ' ), true );
0 commit comments