Merge pull request #22838 from HannahShiSFB/compression-interop-test

PHP: add interop test case of compression
reviewable/pr22983/r1
Stanley Cheung 5 years ago committed by GitHub
commit 2fc2377b04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 115
      src/php/tests/interop/interop_client.php
  2. 4
      tools/run_tests/run_interop_tests.py

@ -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.
*
@ -256,6 +303,68 @@ function clientStreaming($stub)
'aggregated_payload_size was incorrect');
}
/**
* Run the client_compressed_streaming test.
*
* @param $stub Stub object that has service methods
*/
function clientCompressedStreaming($stub)
{
$request_len = 27182;
$request2_len = 45904;
$response_len = 73086;
$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\StreamingInputCallRequest([
'payload' => $payload,
'expect_compressed' => $trueBoolValue, // lie
]);
$call = $stub->StreamingInputCall();
$call->write($request);
list($result, $status) = $call->wait();
hardAssert(
$status->code === GRPC\STATUS_INVALID_ARGUMENT,
'Received unexpected StreamingInputCall status code: ' .
$status->code
);
// 2. write compressed message
$call = $stub->StreamingInputCall([
'grpc-internal-encoding-request' => ['gzip'],
]);
$request->setExpectCompressed($trueBoolValue);
$call->write($request);
// 3. write uncompressed message
$payload2 = new Grpc\Testing\Payload([
'body' => str_repeat("\0", $request2_len),
]);
$request->setPayload($payload2);
$request->setExpectCompressed($falseBoolValue);
$call->write($request, [
'flags' => 0x02 // GRPC_WRITE_NO_COMPRESS
]);
// 4. verify response
list($result, $status) = $call->wait();
hardAssertIfStatusOk($status);
hardAssert(
$result->getAggregatedPayloadSize() === $response_len,
'aggregated_payload_size was incorrect'
);
}
/**
* Run the server_streaming test.
*
@ -673,6 +782,12 @@ function interop_main($args, $stub = false)
case 'per_rpc_creds':
perRpcCreds($stub, $args);
break;
case 'client_compressed_unary':
clientCompressedUnary($stub);
break;
case 'client_compressed_streaming':
clientCompressedStreaming($stub);
break;
default:
echo "Unsupported test case $test_case\n";
exit(1);

@ -499,7 +499,7 @@ class PHPLanguage:
return {}
def unimplemented_test_cases(self):
return _SKIP_COMPRESSION + \
return _SKIP_SERVER_COMPRESSION + \
_SKIP_DATA_FRAME_PADDING + \
_SKIP_SPECIAL_STATUS_MESSAGE + \
_SKIP_GOOGLE_DEFAULT_CREDS + \
@ -528,7 +528,7 @@ class PHP7Language:
return {}
def unimplemented_test_cases(self):
return _SKIP_COMPRESSION + \
return _SKIP_SERVER_COMPRESSION + \
_SKIP_DATA_FRAME_PADDING + \
_SKIP_SPECIAL_STATUS_MESSAGE + \
_SKIP_GOOGLE_DEFAULT_CREDS + \

Loading…
Cancel
Save