add test case of compression

pull/22838/head
Hannah Shi 5 years ago
parent 28a0c0ff00
commit 662c44cbc3
  1. 50
      src/php/tests/interop/interop_client.php

@ -116,6 +116,53 @@ function performLargeUnary($stub, $fillUsername = false,
return $result; 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. * Run the service account credentials auth test.
* *
@ -673,6 +720,9 @@ function interop_main($args, $stub = false)
case 'per_rpc_creds': case 'per_rpc_creds':
perRpcCreds($stub, $args); perRpcCreds($stub, $args);
break; break;
case 'client_compressed_unary':
clientCompressedUnary($stub);
break;
default: default:
echo "Unsupported test case $test_case\n"; echo "Unsupported test case $test_case\n";
exit(1); exit(1);

Loading…
Cancel
Save