test: retry console team fixtures on organization lock contention

Console organization creation is serialized behind the
console:organizations:create distributed lock with a 3 second acquire
timeout. The e2e suites run under ParaTest --functional, so many test
processes create their console organization fixture at the same time,
and a request that cannot take the lock in time answers 409
general_resource_locked. createTeamFixture treated anything other than
201 as the self-hosted refusal and failed on assertSame(403, 409), most
recently in Teams / testTeamMembershipPerms on an unrelated PR.

A 409 says nothing about whether the organization was allowed, only
that the request should be retried, which is what the error message
asks callers to do. Retry the create while it reports lock contention
before deciding between the public API result and direct seeding.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Chirag AggarwalandClaude committed 2026-09-14 09:58:01 +01:00
1 parent 09ee57987e
commit a654ff248e
1 file changed
+13 -2
+13 -2
View File
@@ -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']);