diff options
author | Stanley Cheung <stanleycheung@google.com> | 2015-08-12 16:28:58 -0700 |
---|---|---|
committer | Stanley Cheung <stanleycheung@google.com> | 2015-08-13 10:48:32 -0700 |
commit | 4c5c7b8647522fa9f21b33add09ae4b7d5ca6512 (patch) | |
tree | a87337cef2ce29a7437f4fb8b7ddf860420e19ec /src/php | |
parent | a63fdd01263f29bdf2ec0d0975f7386370de47ba (diff) |
php: add more tests
Diffstat (limited to 'src/php')
-rw-r--r-- | src/php/ext/grpc/channel.c | 8 | ||||
-rwxr-xr-x | src/php/tests/unit_tests/EndToEndTest.php | 31 |
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); } } |