diff --git a/tests/e2e/Scopes/Scope.php b/tests/e2e/Scopes/Scope.php index 7b15867cea..8e1c86e968 100644 --- a/tests/e2e/Scopes/Scope.php +++ b/tests/e2e/Scopes/Scope.php @@ -72,8 +72,19 @@ abstract class Scope extends TestCase // The first organization of a self-hosted instance, and every organization on an // edition without the instance limit, comes from the public API. Only a refusal - // falls through to seeding the rows directly. - $team = $this->client->call(Client::METHOD_POST, '/teams', $headers, $params); + // falls through to seeding the rows directly. Creation is serialized behind an + // instance-wide lock, and parallel test processes contend for it, so a 409 asks + // for a retry rather than answering whether the organization was allowed. + $deadline = \microtime(true) + 10.0; + do { + $team = $this->client->call(Client::METHOD_POST, '/teams', $headers, $params); + $locked = $team['headers']['status-code'] === 409 + && ($team['body']['type'] ?? '') === 'general_resource_locked'; + if ($locked) { + \usleep(200_000); + } + } while ($locked && \microtime(true) < $deadline); + if ($team['headers']['status-code'] === 201) { $response = $this->client->call(Client::METHOD_GET, '/teams/' . $team['body']['$id'], $headers); $this->assertSame(200, $response['headers']['status-code']);