php: add more tests

pull/2877/head
Stanley Cheung 9 years ago
parent a63fdd0126
commit 4c5c7b8647
  1. 8
      src/php/ext/grpc/channel.c
  2. 31
      src/php/tests/unit_tests/EndToEndTest.php

@ -230,6 +230,8 @@ PHP_METHOD(Channel, getConnectivityState) {
* Watch the connectivity state of the channel until it changed
* @param long The previous connectivity state of the channel
* @param Timeval The deadline this function should wait until
* @return bool If the connectivity state changes from last_state
* before deadline
*/
PHP_METHOD(Channel, watchConnectivityState) {
wrapped_grpc_channel *channel =
@ -255,11 +257,9 @@ PHP_METHOD(Channel, watchConnectivityState) {
completion_queue, NULL,
gpr_inf_future(GPR_CLOCK_REALTIME));
if (!event.success) {
zend_throw_exception(spl_ce_LogicException,
"watchConnectivityState failed",
1 TSRMLS_CC);
RETURN_BOOL(0);
}
return;
RETURN_BOOL(1);
}
/**

@ -158,13 +158,30 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
$this->assertTrue($this->channel->getConnectivityState() == Grpc\CHANNEL_IDLE);
}
public function testWatchConnectivityState() {
$old_state = $this->channel->getConnectivityState(true);
$deadline = microtime(true) * 1000000 + 500000;
$this->channel->watchConnectivityState(
$old_state,
new Grpc\Timeval($deadline));
public function testWatchConnectivityStateFailed() {
$idle_state = $this->channel->getConnectivityState(true);
$this->assertTrue($idle_state == Grpc\CHANNEL_IDLE);
$now = Grpc\Timeval::now();
$delta = new Grpc\Timeval(1);
$deadline = $now->add($delta);
$this->assertFalse($this->channel->watchConnectivityState(
$idle_state, $deadline));
}
public function testWatchConnectivityStateSuccess() {
$idle_state = $this->channel->getConnectivityState(true);
$this->assertTrue($idle_state == Grpc\CHANNEL_IDLE);
$now = Grpc\Timeval::now();
$delta = new Grpc\Timeval(100000);
$deadline = $now->add($delta);
$this->assertTrue($this->channel->watchConnectivityState(
$idle_state, $deadline));
$new_state = $this->channel->getConnectivityState();
$this->assertTrue($old_state != $new_state);
$this->assertTrue($idle_state != $new_state);
}
}

Loading…
Cancel
Save