aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/php/ext/grpc/channel.c8
-rwxr-xr-xsrc/php/tests/unit_tests/EndToEndTest.php31
2 files changed, 28 insertions, 11 deletions
diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c
index ebb1320c86..5e0de2959a 100644
--- a/src/php/ext/grpc/channel.c
+++ b/src/php/ext/grpc/channel.c
@@ -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);
}
/**
diff --git a/src/php/tests/unit_tests/EndToEndTest.php b/src/php/tests/unit_tests/EndToEndTest.php
index 3a44fc7766..df4cebc966 100755
--- a/src/php/tests/unit_tests/EndToEndTest.php
+++ b/src/php/tests/unit_tests/EndToEndTest.php
@@ -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);
}
}