mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
fix: Add retry logic for 401 errors in ProjectCustom::getProject
Under high parallel load, authentication can transiently fail with 401. Add retry logic with delays to handle these transient failures. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
ce200d20d4
commit
6be719c9d4
@@ -24,34 +24,68 @@ trait ProjectCustom
|
||||
return self::$project;
|
||||
}
|
||||
|
||||
$team = $this->client->call(Client::METHOD_POST, '/teams', [
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
||||
'x-appwrite-project' => 'console',
|
||||
], [
|
||||
'teamId' => ID::unique(),
|
||||
'name' => 'Demo Project Team',
|
||||
]);
|
||||
$this->assertEquals(201, $team['headers']['status-code']);
|
||||
$this->assertEquals('Demo Project Team', $team['body']['name']);
|
||||
$this->assertNotEmpty($team['body']['$id']);
|
||||
// Small delay to ensure session is fully propagated under parallel load
|
||||
usleep(100000); // 100ms
|
||||
|
||||
$project = $this->client->call(Client::METHOD_POST, '/projects', [
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
||||
'x-appwrite-project' => 'console',
|
||||
], [
|
||||
'projectId' => ID::unique(),
|
||||
'region' => System::getEnv('_APP_REGION', 'default'),
|
||||
'name' => 'Demo Project',
|
||||
'teamId' => $team['body']['$id'],
|
||||
'description' => 'Demo Project Description',
|
||||
'url' => 'https://appwrite.io',
|
||||
]);
|
||||
$maxRetries = 3;
|
||||
$team = null;
|
||||
$teamId = ID::unique();
|
||||
|
||||
$this->assertEquals(201, $project['headers']['status-code']);
|
||||
for ($i = 0; $i < $maxRetries; $i++) {
|
||||
$team = $this->client->call(Client::METHOD_POST, '/teams', [
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
||||
'x-appwrite-project' => 'console',
|
||||
], [
|
||||
'teamId' => $teamId,
|
||||
'name' => 'Demo Project Team',
|
||||
]);
|
||||
|
||||
if ($team['headers']['status-code'] === 201 || $team['headers']['status-code'] === 409) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($team['headers']['status-code'] === 401 && $i < $maxRetries - 1) {
|
||||
usleep(500000); // 500ms delay before retry
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertContains($team['headers']['status-code'], [201, 409], 'Team creation failed with status: ' . $team['headers']['status-code']);
|
||||
if ($team['headers']['status-code'] === 201) {
|
||||
$this->assertEquals('Demo Project Team', $team['body']['name']);
|
||||
$this->assertNotEmpty($team['body']['$id']);
|
||||
$teamId = $team['body']['$id'];
|
||||
}
|
||||
|
||||
$project = null;
|
||||
for ($i = 0; $i < $maxRetries; $i++) {
|
||||
$project = $this->client->call(Client::METHOD_POST, '/projects', [
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
||||
'x-appwrite-project' => 'console',
|
||||
], [
|
||||
'projectId' => ID::unique(),
|
||||
'region' => System::getEnv('_APP_REGION', 'default'),
|
||||
'name' => 'Demo Project',
|
||||
'teamId' => $teamId,
|
||||
'description' => 'Demo Project Description',
|
||||
'url' => 'https://appwrite.io',
|
||||
]);
|
||||
|
||||
if ($project['headers']['status-code'] === 201) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($project['headers']['status-code'] === 401 && $i < $maxRetries - 1) {
|
||||
usleep(500000); // 500ms delay before retry
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals(201, $project['headers']['status-code'], 'Project creation failed with status: ' . $project['headers']['status-code']);
|
||||
$this->assertNotEmpty($project['body']);
|
||||
|
||||
$key = $this->client->call(Client::METHOD_POST, '/projects/' . $project['body']['$id'] . '/keys', [
|
||||
|
||||
Reference in New Issue
Block a user