Skip to content

Commit

Permalink
Fixed random message assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Mar 20, 2018
1 parent f6b298a commit a23f639
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function makeClient()
]
]);

sleep(3); // prevent receiving previous messages from queue
usleep(100); // keep queue for more real case

return stream_socket_client('ssl://localhost:' . static::PORT, $errorNumber, $errorString, null, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $context);
}
Expand Down Expand Up @@ -204,9 +204,18 @@ public function testConnector()
socket_write($socket, Frame::encode('connector:hello'));
socket_close($socket);

$data = Frame::decode($client);
$this->assertArrayHasKey('payload', $data);
$this->assertEquals('connector:hello', $data['payload']);
$found = false;

while (!$found) {
$data = Frame::decode($client);
$this->assertArrayHasKey('payload', $data);

if ($data['payload'] == 'connector:hello') {
$found = true;
}
}

$this->assertTrue($found);

fclose($client);
}
Expand Down

0 comments on commit a23f639

Please sign in to comment.