Fix flaky realtime tests by adjusting websocket connection parameters… (#12540)

* Fix flaky realtime tests by adjusting websocket connection parameters and refreshing user cache

* updated
This commit is contained in:
ArnabChatterjee20k authored and GitHub committed 2026-06-09 08:30:00 +05:30
1 parent 8a63bfadbb
commit ce48d15919
3 files changed
+43 -19

No files matched your search

@@ -611,7 +611,7 @@ final class RealtimeConsoleClientTest extends Scope
$client = $this->getWebsocket(['console'], [
'origin' => 'http://localhost',
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
], $projectId);
], $projectId, null, 10);
$response = json_decode($client->receive(), true);
@@ -915,7 +915,7 @@ final class RealtimeConsoleClientTest extends Scope
$client = $this->getWebsocket(['console'], [
'origin' => 'http://localhost',
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
], $projectId);
], $projectId, null, 10);
$response = json_decode($client->receive(), true);
@@ -983,7 +983,7 @@ final class RealtimeConsoleClientTest extends Scope
$client = $this->getWebsocket(['console'], [
'origin' => 'http://localhost',
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
], 'console');
], 'console', null, 10);
$response = json_decode($client->receive(), true);
@@ -1044,7 +1044,7 @@ final class RealtimeConsoleClientTest extends Scope
$client = $this->getWebsocket(['console'], [
'origin' => 'http://localhost',
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
], $projectId);
], $projectId, null, 30);
$response = json_decode($client->receive(), true);
@@ -743,6 +743,30 @@ final class RealtimeCustomClientTest extends Scope
$this->assertNotEmpty($response['data']['payload']);
$client->close();
/**
* The password change and password-recovery completion above invalidate
* every existing session of this user, including the one cached in
* self::$user. Re-authenticate the SAME account (its email is now
* torsten@appwrite.io and its password 'test-recovery' after the flow
* above) and refresh only the cached session, so later tests in this
* process keep the same user $id but connect with a valid session
* instead of falling back to a guest connection.
*/
$refreshedSession = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], [
'email' => 'torsten@appwrite.io',
'password' => 'test-recovery',
]);
$this->assertEquals(201, $refreshedSession['headers']['status-code']);
self::$user[$projectId]['email'] = 'torsten@appwrite.io';
self::$user[$projectId]['session'] = $refreshedSession['cookies']['a_session_' . $projectId];
self::$user[$projectId]['sessionId'] = $refreshedSession['body']['$id'];
}
public function testChannelDatabase()
@@ -3141,7 +3165,7 @@ final class RealtimeCustomClientTest extends Scope
$client = $this->getWebsocket(['documents'], [
'origin' => 'http://localhost',
'cookie' => 'a_session_' . $projectId . '=' . $session
]);
], null, null, 10);
$response = json_decode($client->receive(), true);
@@ -3408,7 +3432,7 @@ final class RealtimeCustomClientTest extends Scope
], [
'origin' => 'http://localhost',
'cookie' => 'a_session_' . $projectId . '=' . $session,
]);
], null, null, 10);
$connected = json_decode($legacyClient->receive(), true);
$this->assertEquals('connected', $connected['type']);
@@ -3502,7 +3526,7 @@ final class RealtimeCustomClientTest extends Scope
], [
'origin' => 'http://localhost',
'cookie' => 'a_session_' . $projectId . '=' . $session,
]);
], null, null, 10);
$connected = json_decode($tablesClient->receive(), true);
$this->assertEquals('connected', $connected['type']);
@@ -3576,7 +3600,7 @@ final class RealtimeCustomClientTest extends Scope
], [
'origin' => 'http://localhost',
'cookie' => 'a_session_' . $projectId . '=' . $session,
]);
], null, null, 10);
$connected = json_decode($documentsClient->receive(), true);
$this->assertEquals('connected', $connected['type']);
@@ -165,7 +165,7 @@ trait RealtimeQueryBase
'cookie' => 'a_session_' . $projectId . '=' . $session,
], null, [
Query::equal('$id', [$targetDocumentId])->toString(),
]);
], 10);
$this->assertConnectionStatusIfSupported($client);
@@ -263,7 +263,7 @@ trait RealtimeQueryBase
'cookie' => 'a_session_' . $projectId . '=' . $session,
], null, [
Query::notEqual('$id', [$excludedDocumentId])->toString(),
]);
], 10);
$this->assertConnectionStatusIfSupported($client);
@@ -358,7 +358,7 @@ trait RealtimeQueryBase
'cookie' => 'a_session_' . $projectId . '=' . $session,
], null, [
Query::greaterThan('score', 50)->toString(),
]);
], 10);
$this->assertConnectionStatusIfSupported($client);
@@ -452,7 +452,7 @@ trait RealtimeQueryBase
'cookie' => 'a_session_' . $projectId . '=' . $session,
], null, [
Query::lessThan('age', 18)->toString(),
]);
], 10);
$this->assertConnectionStatusIfSupported($client);
@@ -546,7 +546,7 @@ trait RealtimeQueryBase
'cookie' => 'a_session_' . $projectId . '=' . $session,
], null, [
Query::greaterThanEqual('priority', 5)->toString(),
]);
], 10);
$this->assertConnectionStatusIfSupported($client);
@@ -658,7 +658,7 @@ trait RealtimeQueryBase
'cookie' => 'a_session_' . $projectId . '=' . $session,
], null, [
Query::lessThanEqual('level', 10)->toString(),
]);
], 10);
$this->assertConnectionStatusIfSupported($client);
@@ -771,7 +771,7 @@ trait RealtimeQueryBase
'cookie' => 'a_session_' . $projectId . '=' . $session,
], null, [
Query::isNull('description')->toString(),
]);
], 10);
$this->assertConnectionStatusIfSupported($client);
@@ -865,7 +865,7 @@ trait RealtimeQueryBase
'cookie' => 'a_session_' . $projectId . '=' . $session,
], null, [
Query::isNotNull('email')->toString(),
]);
], 10);
$this->assertConnectionStatusIfSupported($client);
@@ -976,7 +976,7 @@ trait RealtimeQueryBase
Query::equal('status', ['active']),
Query::greaterThan('priority', 5)
])->toString(),
]);
], 10);
$this->assertConnectionStatusIfSupported($client);
@@ -1099,7 +1099,7 @@ trait RealtimeQueryBase
Query::equal('type', ['urgent']),
Query::equal('type', ['critical'])
])->toString(),
]);
], 10);
$this->assertConnectionStatusIfSupported($client);
@@ -1233,7 +1233,7 @@ trait RealtimeQueryBase
]),
Query::greaterThanEqual('score', 80)
])->toString(),
]);
], 10);
$this->assertConnectionStatusIfSupported($client);