From 662c44cbc3020f35d972b0cdad36cf0cdc144dda Mon Sep 17 00:00:00 2001 From: Hannah Shi Date: Fri, 1 May 2020 07:44:37 +0000 Subject: [PATCH] =?UTF-8?q?add=20test=20case=20of=C2=A0compression?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/php/tests/interop/interop_client.php | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/php/tests/interop/interop_client.php b/src/php/tests/interop/interop_client.php index e4750475dc5..88be899fdd1 100755 --- a/src/php/tests/interop/interop_client.php +++ b/src/php/tests/interop/interop_client.php @@ -116,6 +116,53 @@ function performLargeUnary($stub, $fillUsername = false, return $result; } +/** + * Run the client_compressed_unary test. + * + * @param $stub Stub object that has service methods + */ +function clientCompressedUnary($stub) +{ + $request_len = 271828; + $response_len = 314159; + $falseBoolValue = new Grpc\Testing\BoolValue(['value' => false]); + $trueBoolValue = new Grpc\Testing\BoolValue(['value' => true]); + // 1. Probing for compression-checks support + $payload = new Grpc\Testing\Payload([ + 'body' => str_repeat("\0", $request_len), + ]); + $request = new Grpc\Testing\SimpleRequest([ + 'payload' => $payload, + 'response_size' => $response_len, + 'expect_compressed' => $trueBoolValue, // lie + ]); + list($result, $status) = $stub->UnaryCall($request, [], [])->wait(); + hardAssert( + $status->code === GRPC\STATUS_INVALID_ARGUMENT, + 'Received unexpected UnaryCall status code: ' . + $status->code + ); + // 2. with/without compressed message + foreach ([true, false] as $compression) { + $request->setExpectCompressed($compression ? $trueBoolValue : $falseBoolValue); + $metadata = $compression ? [ + 'grpc-internal-encoding-request' => ['gzip'], + ] : []; + list($result, $status) = $stub->UnaryCall($request, $metadata, [])->wait(); + hardAssertIfStatusOk($status); + hardAssert($result !== null, 'Call returned a null response'); + $payload = $result->getPayload(); + hardAssert( + strlen($payload->getBody()) === $response_len, + 'Payload had the wrong length' + ); + hardAssert( + $payload->getBody() === str_repeat("\0", $response_len), + 'Payload had the wrong content' + ); + } +} + /** * Run the service account credentials auth test. * @@ -673,6 +720,9 @@ function interop_main($args, $stub = false) case 'per_rpc_creds': perRpcCreds($stub, $args); break; + case 'client_compressed_unary': + clientCompressedUnary($stub); + break; default: echo "Unsupported test case $test_case\n"; exit(1);