Skip to content

Add support for 'Max retry duration' and allow for unlimited tasks #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 17, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
marickvantuil committed Dec 12, 2021
commit d165daf84f22330e14fb4b3b048bc14166902416
64 changes: 64 additions & 0 deletions tests/TaskHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests;

use Carbon\Carbon;
use Firebase\JWT\JWT;
use Firebase\JWT\SignatureInvalidException;
use Google\Cloud\Tasks\V2\Attempt;
Expand Down Expand Up @@ -279,7 +280,70 @@ public function hasMaxRetryDuration() {

$this->cloudTasksClient->shouldNotHaveReceived('deleteTask');
}
}

/**
* @test
* @testWith [{"retryCount": 1, "shouldHaveFailed": false}]
* [{"retryCount": 2, "shouldHaveFailed": false}]
* [{"retryCount": 2, "travelSeconds": 29, "shouldHaveFailed": false}]
* [{"retryCount": 2, "travelSeconds": 31, "shouldHaveFailed": true}]
*/
public function job_max_attempts_is_ignored_if_has_retry_until($example)
{
// Arrange
$this->request->headers->add(['X-CloudTasks-TaskRetryCount' => $example['retryCount']]);

$now = Carbon::now()->getTimestamp();
if (array_key_exists('travelSeconds', $example)) {
Carbon::setTestNow(Carbon::now()->addSeconds($example['travelSeconds']));
}

$this->cloudTasksClient->shouldReceive('getQueue')
->byDefault()
->andReturn(new class() {
public function getRetryConfig() {
return new class {
public function getMaxAttempts() {
return 3;
}

public function hasMaxRetryDuration() {
return true;
}

public function getMaxRetryDuration() {
return new class {
public function getSeconds() {
return 30;
}
};
}
};
}
});

$this->cloudTasksClient
->shouldReceive('getTask')
->byDefault()
->andReturn(new class {
public function getFirstAttempt() {
return (new Attempt())
->setDispatchTime(new Timestamp([
'seconds' => time(),
]));
}
});

rescue(function () {
$this->handler->handle($this->failingJob());
});

if ($example['shouldHaveFailed']) {
$this->cloudTasksClient->shouldHaveReceived('deleteTask');
} else {
$this->cloudTasksClient->shouldNotHaveReceived('deleteTask');
}
}

private function simpleJob()
Expand Down