aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/tests
diff options
context:
space:
mode:
authorGravatar Stanley Cheung <stanleycheung@google.com>2015-06-15 11:45:00 -0700
committerGravatar Stanley Cheung <stanleycheung@google.com>2015-06-15 17:22:39 -0700
commitcc019af9cc2951bf7e0cdc17fb118e239dc785c3 (patch)
treee2fa22fb3dac1de958b5feddfaae413806a1c273 /src/php/tests
parent0d6cf992e8f840ae257c039f15fc045e9605090f (diff)
add PHP timeout interop test
Diffstat (limited to 'src/php/tests')
-rwxr-xr-xsrc/php/tests/interop/interop_client.php21
-rwxr-xr-xsrc/php/tests/unit_tests/TimevalTest.php22
2 files changed, 43 insertions, 0 deletions
diff --git a/src/php/tests/interop/interop_client.php b/src/php/tests/interop/interop_client.php
index 9aee01cd4d..2041577557 100755
--- a/src/php/tests/interop/interop_client.php
+++ b/src/php/tests/interop/interop_client.php
@@ -270,6 +270,24 @@ function cancelAfterFirstResponse($stub) {
'Call status was not CANCELLED');
}
+function timeoutOnSleepingServer($stub) {
+ $call = $stub->FullDuplexCall(array('timeout' => 500000));
+ $request = new grpc\testing\StreamingOutputCallRequest();
+ $request->setResponseType(grpc\testing\PayloadType::COMPRESSABLE);
+ $response_parameters = new grpc\testing\ResponseParameters();
+ $response_parameters->setSize(8);
+ $request->addResponseParameters($response_parameters);
+ $payload = new grpc\testing\Payload();
+ $payload->setBody(str_repeat("\0", 9));
+ $request->setPayload($payload);
+
+ $call->write($request);
+ $response = $call->read();
+
+ hardAssert($call->getStatus()->code === Grpc\STATUS_DEADLINE_EXCEEDED,
+ 'Call status was not DEADLINE_EXCEEDED');
+}
+
$args = getopt('', array('server_host:', 'server_port:', 'test_case:',
'server_host_override:', 'oauth_scope:',
'default_service_account:'));
@@ -341,6 +359,9 @@ switch ($args['test_case']) {
case 'cancel_after_first_response':
cancelAfterFirstResponse($stub);
break;
+ case 'timeout_on_sleeping_server':
+ timeoutOnSleepingServer($stub);
+ break;
case 'service_account_creds':
serviceAccountCreds($stub, $args);
break;
diff --git a/src/php/tests/unit_tests/TimevalTest.php b/src/php/tests/unit_tests/TimevalTest.php
index a8bfcf0ac4..7b4925cad6 100755
--- a/src/php/tests/unit_tests/TimevalTest.php
+++ b/src/php/tests/unit_tests/TimevalTest.php
@@ -61,4 +61,26 @@ class TimevalTest extends PHPUnit_Framework_TestCase{
$this->assertLessThan(0, Grpc\Timeval::compare($zero, $now));
$this->assertLessThan(0, Grpc\Timeval::compare($now, $future));
}
+
+ public function testNowAndAdd() {
+ $now = Grpc\Timeval::now();
+ $delta = new Grpc\Timeval(1000);
+ $deadline = $now->add($delta);
+ $this->assertGreaterThan(0, Grpc\Timeval::compare($deadline, $now));
+ }
+
+ public function testNowAndSubtract() {
+ $now = Grpc\Timeval::now();
+ $delta = new Grpc\Timeval(1000);
+ $deadline = $now->subtract($delta);
+ $this->assertLessThan(0, Grpc\Timeval::compare($deadline, $now));
+ }
+
+ public function testAddAndSubtract() {
+ $now = Grpc\Timeval::now();
+ $delta = new Grpc\Timeval(1000);
+ $deadline = $now->add($delta);
+ $back_to_now = $deadline->subtract($delta);
+ $this->assertSame(0, Grpc\Timeval::compare($back_to_now, $now));
+ }
}