|  | 
| 2 | 2 | 
 | 
| 3 | 3 | namespace Tests; | 
| 4 | 4 | 
 | 
|  | 5 | +use Carbon\Carbon; | 
| 5 | 6 | use Firebase\JWT\JWT; | 
| 6 | 7 | use Firebase\JWT\SignatureInvalidException; | 
| 7 | 8 | use Google\Cloud\Tasks\V2\Attempt; | 
| @@ -279,7 +280,70 @@ public function hasMaxRetryDuration() { | 
| 279 | 280 | 
 | 
| 280 | 281 |             $this->cloudTasksClient->shouldNotHaveReceived('deleteTask'); | 
| 281 | 282 |         } | 
|  | 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 | +                        } | 
| 282 | 314 | 
 | 
|  | 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 | +        } | 
| 283 | 347 |     } | 
| 284 | 348 | 
 | 
| 285 | 349 |     private function simpleJob() | 
|  | 
0 commit comments