mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
fix: remove destructive assertEventually wrapping around receive()
WebSocket receive() consumes a fresh message on each call, so retrying inside assertEventually desynchronizes subsequent assertions instead of re-checking the same message. Keep the increased socket timeout to tolerate slow connections, but use direct receive() calls again to stay consistent with RealtimeConsoleClientTest::testManualAuthentication. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
6391764eb1
commit
0a840ef80f
@@ -181,21 +181,14 @@ class RealtimeCustomClientTest extends Scope
|
||||
$client = $this->getWebsocket(['account'], [
|
||||
'origin' => 'http://localhost'
|
||||
], timeout: 10);
|
||||
$assertResponseEventually = function (callable $assertion) use ($client): void {
|
||||
$this->assertEventually(function () use ($client, $assertion) {
|
||||
$response = \json_decode($client->receive(), true);
|
||||
$this->assertIsArray($response);
|
||||
$assertion($response);
|
||||
}, 10000, 250);
|
||||
};
|
||||
$assertResponseEventually(function (array $response): void {
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('connected', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertCount(1, $response['data']['channels']);
|
||||
$this->assertContains('account', $response['data']['channels']);
|
||||
});
|
||||
$response = json_decode($client->receive(), true);
|
||||
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('connected', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertCount(1, $response['data']['channels']);
|
||||
$this->assertContains('account', $response['data']['channels']);
|
||||
|
||||
$client->send(\json_encode([
|
||||
'type' => 'authentication',
|
||||
@@ -204,16 +197,16 @@ class RealtimeCustomClientTest extends Scope
|
||||
]
|
||||
]));
|
||||
|
||||
$assertResponseEventually(function (array $response) use ($userId): void {
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('response', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertEquals('authentication', $response['data']['to']);
|
||||
$this->assertTrue($response['data']['success']);
|
||||
$this->assertNotEmpty($response['data']['user']);
|
||||
$this->assertEquals($userId, $response['data']['user']['$id']);
|
||||
});
|
||||
$response = json_decode($client->receive(), true);
|
||||
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('response', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertEquals('authentication', $response['data']['to']);
|
||||
$this->assertTrue($response['data']['success']);
|
||||
$this->assertNotEmpty($response['data']['user']);
|
||||
$this->assertEquals($userId, $response['data']['user']['$id']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
@@ -225,28 +218,28 @@ class RealtimeCustomClientTest extends Scope
|
||||
]
|
||||
]));
|
||||
|
||||
$assertResponseEventually(function (array $response): void {
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('error', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertEquals(1003, $response['data']['code']);
|
||||
$this->assertEquals('Session is not valid.', $response['data']['message']);
|
||||
});
|
||||
$response = json_decode($client->receive(), true);
|
||||
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('error', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertEquals(1003, $response['data']['code']);
|
||||
$this->assertEquals('Session is not valid.', $response['data']['message']);
|
||||
|
||||
$client->send(\json_encode([
|
||||
'type' => 'authentication',
|
||||
'data' => []
|
||||
]));
|
||||
|
||||
$assertResponseEventually(function (array $response): void {
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('error', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertEquals(1003, $response['data']['code']);
|
||||
$this->assertEquals('Payload is not valid.', $response['data']['message']);
|
||||
});
|
||||
$response = json_decode($client->receive(), true);
|
||||
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('error', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertEquals(1003, $response['data']['code']);
|
||||
$this->assertEquals('Payload is not valid.', $response['data']['message']);
|
||||
|
||||
$client->send(\json_encode([
|
||||
'type' => 'unknown',
|
||||
@@ -255,27 +248,27 @@ class RealtimeCustomClientTest extends Scope
|
||||
]
|
||||
]));
|
||||
|
||||
$assertResponseEventually(function (array $response): void {
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('error', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertEquals(1003, $response['data']['code']);
|
||||
$this->assertEquals('Message type is not valid.', $response['data']['message']);
|
||||
});
|
||||
$response = json_decode($client->receive(), true);
|
||||
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('error', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertEquals(1003, $response['data']['code']);
|
||||
$this->assertEquals('Message type is not valid.', $response['data']['message']);
|
||||
|
||||
$client->send(\json_encode([
|
||||
'test' => '123',
|
||||
]));
|
||||
|
||||
$assertResponseEventually(function (array $response): void {
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('error', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertEquals(1003, $response['data']['code']);
|
||||
$this->assertEquals('Message format is not valid.', $response['data']['message']);
|
||||
});
|
||||
$response = json_decode($client->receive(), true);
|
||||
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('error', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertEquals(1003, $response['data']['code']);
|
||||
$this->assertEquals('Message format is not valid.', $response['data']['message']);
|
||||
|
||||
|
||||
$client->close();
|
||||
|
||||
Reference in New Issue
Block a user