Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sending heart beat requests and fix invalid heart beat timezone #10

Merged
merged 2 commits into from
May 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,22 @@ public function sendInitRequest($class, $name)
)));
}

public function sendHeartBeatRequest(\DateTime $dt)
{
// TODO: legacy protocol uses a QTime, datastream protocol QDateTime
$this->send($this->protocol->writeVariantList(array(
Protocol::REQUEST_HEARTBEAT,
$dt
), array(1 => Types::TYPE_QTIME)));
}

public function sendHeartBeatReply(\DateTime $dt)
{
// legacy protocol actually uses a QTime instead of QDateTime, but accepts both
// TODO: legacy protocol uses a QTime, datastream protocol QDateTime
$this->send($this->protocol->writeVariantList(array(
Protocol::REQUEST_HEARTBEATREPLY,
$dt
)));
), array(1 => Types::TYPE_QTIME)));
}

public function sendBufferInput($bufferInfo, $input)
Expand Down
28 changes: 28 additions & 0 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Clue\React\Block\Blocker;
use Clue\React\Quassel\Client;
use React\Promise\Deferred;
use Clue\React\Quassel\Io\Protocol;

class FunctionalTest extends TestCase
{
Expand Down Expand Up @@ -124,6 +125,33 @@ public function testSendClientLogin(Client $client, $message)
return self::$blocker->awaitOne($deferred->promise());
}

/**
* @depends testCreateClient
*
* @param Client $client
*/
public function testSendHeartBeat(Client $client)
{
$time = new \DateTime();

$deferred = new Deferred();

$callback = function ($message) use ($deferred, &$callback, $client) {
if (isset($message[0]) && $message[0] === Protocol::REQUEST_HEARTBEATREPLY) {
$client->removeListener('message', $callback);
$deferred->resolve($message[1]);
}
};

$client->on('message', $callback);

$client->sendHeartBeatRequest($time);

$received = self::$blocker->awaitOne($deferred->promise());

$this->assertEquals($time, $received);
}

/**
* @depends testCreateClient
*/
Expand Down