Skip to content

Commit

Permalink
Merge branch 'hotfix/subscription-monitor'
Browse files Browse the repository at this point in the history
  • Loading branch information
tidal committed Oct 2, 2016
2 parents 010fa8b + 6436d8a commit b27afce
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 175 deletions.
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 80 additions & 3 deletions tests/integration/crossbar/CrossbarTestingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Thruway\Connection;
use React\EventLoop\Factory as LoopFactory;
use React\EventLoop\LoopInterface;
use Thruway\ClientSession;
use Tidal\WampWatch\Adapter\Thruway\ClientSession as Adapter;

trait CrossbarTestingTrait
{
Expand All @@ -24,6 +26,11 @@ trait CrossbarTestingTrait
*/
private $connection;

/**
* @var Adapter
*/
private $clientSession;

/**
* @var LoopInterface
*/
Expand All @@ -39,17 +46,29 @@ trait CrossbarTestingTrait
*/
private $monitoredSessionId = -2;

/**
* @var string
*/
private $testTopicName = 'foo';

private function setupConnection()
{

$this->clientSessionId = -1;
$this->monitoredSessionId = -2;

$this->setupTestTopicName();

Logger::set(new NullLogger());

$this->loop = LoopFactory::create();
$this->getConnection()->on('error', function ($reason) {
echo "The connected has closed with error: {$reason}\n";
});

$this->connection = $this->createConnection($this->loop);
$this->getConnection()->on('open', function (ClientSession $session) {
$this->clientSession = $this->createSessionAdapter($session);
$this->clientSessionId = $session->getSessionId();
});

}

Expand All @@ -61,7 +80,7 @@ private function setupConnection()
private function createConnection(LoopInterface $loop = null)
{
if ($loop === null) {
$loop = LoopFactory::create();
$loop = $this->getLoop();
}

return new Connection(
Expand All @@ -72,4 +91,62 @@ private function createConnection(LoopInterface $loop = null)
$loop
);
}

/**
* @return \Thruway\Connection
*/
private function createClientConnection()
{
$connection = $this->createConnection();

$connection->on('error', function ($reason) {
echo "The client connection has closed with error: {$reason}\n";
});
$this->getConnection()->on('close', [$connection, 'close']);
$connection->on('open', function ($session) {
$this->clientSession = $this->createSessionAdapter($session);
});

return $connection;
}

private function setupTestTopicName()
{
$this->testTopicName = "";

$chars = str_split("abcdefghijklmnopqrstuvwxyz");
for ($i = 0; $i < 10; $i++) {
$key = array_rand($chars);
$this->testTopicName .= "" . $chars[$key];
}
}

/**
* @return \React\EventLoop\LoopInterface
*/
private function getLoop()
{
return $this->loop
?: $this->loop = LoopFactory::create();
}

/**
* @param ClientSession $session
*
* @return Adapter
*/
private function createSessionAdapter(ClientSession $session)
{
return new Adapter($session);
}

/**
* @return \Thruway\Connection
*/
public function getConnection()
{
return $this->connection
?: $this->connection = $this->createConnection();
}

}
Loading

0 comments on commit b27afce

Please sign in to comment.