Skip to content

Commit

Permalink
Improve test suite to avoid race condition for functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Aug 1, 2021
1 parent fb0548a commit dc1bf45
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,43 @@ public function testCreateClientWithAuthUrlReceivesSessionInit()
$factory = new Factory();

$url = rawurlencode(self::$username) . ':' . rawurlencode(self::$password) . '@' . self::$host;
$promise = $factory->createClient($url);
$client = Block\await($promise, Loop::get(), 10.0);

$message = $this->awaitMessage($client);
$this->assertEquals('SessionInit', $message->MsgType);
$promise = $factory->createClient($url)->then(function (Client $client) {
return new Promise(function ($resolve, $reject) use ($client) {
$client->once('data', function ($message) use ($client, $resolve) {
$client->close();
$resolve($message);
});

$client->close();
$client->once('error', $reject);
$client->once('close', $reject);
});
});

$message = Block\await($promise, Loop::get(), 10.0);
$this->assertEquals('SessionInit', $message->MsgType);
}

public function testRequestBacklogReceivesBacklog()
{
$factory = new Factory();

$url = rawurlencode(self::$username) . ':' . rawurlencode(self::$password) . '@' . self::$host;
$promise = $factory->createClient($url);
$client = Block\await($promise, Loop::get(), 10.0);
/* @var $client Client */

$message = $this->awaitMessage($client);
$promise = $factory->createClient($url)->then(function (Client $client) {
return new Promise(function ($resolve, $reject) use ($client) {
$client->once('data', function ($message) use ($client, $resolve) {
$resolve(array($client, $message));
});

$client->once('error', $reject);
$client->once('close', $reject);
});
});

list($client, $message) = Block\await($promise, Loop::get(), 10.0);
assert($client instanceof Client);

$this->assertEquals('SessionInit', $message->MsgType);

// try to pick first buffer
Expand Down

0 comments on commit dc1bf45

Please sign in to comment.