Skip to content
Snippets Groups Projects
Commit 42511cfd authored by Makarand Dharmapurikar's avatar Makarand Dharmapurikar
Browse files

Addressed review feedback

1. modified documentation
2. changed test slightly to make it more robust to accidental cache hits
parent 1ed0b8e3
Branches
Tags
No related merge requests found
...@@ -65,21 +65,21 @@ ensure that the proto serialized to zero bytes.* ...@@ -65,21 +65,21 @@ ensure that the proto serialized to zero bytes.*
This test verifies that gRPC requests marked as cacheable use GET verb instead This test verifies that gRPC requests marked as cacheable use GET verb instead
of POST, and that server sets appropriate cache control headers for the response of POST, and that server sets appropriate cache control headers for the response
to be cached by a proxy. This interop test requires that the server is behind to be cached by a proxy. This interop test requires that the server is behind
a caching proxy. It is NOT expected to pass if client is accessing the server a caching proxy. Use of current timestamp in the request prevents accidental
directly. cache matches left over from previous tests.
Server features: Server features:
* [CacheableUnaryCall][] * [CacheableUnaryCall][]
Procedure: Procedure:
1. Client calls CacheableUnaryCall twice, and compares the two responses. 1. Client calls CacheableUnaryCall with `SimpleRequest` request with payload
The server generates a unique response (timestamp) for each request. set to current timestamp.
If the second response was delivered from cache, then both responses will 2. Client calls CacheableUnaryCall with `SimpleRequest` request again
be the same. immediately with the same payload as the previous request.
Client asserts: Client asserts:
* call was successful * Both calls were successful
* responses are the same. * The payload body of both responses is the same.
### large_unary ### large_unary
...@@ -962,6 +962,17 @@ payload body of size `SimpleRequest.response_size` bytes and type as appropriate ...@@ -962,6 +962,17 @@ payload body of size `SimpleRequest.response_size` bytes and type as appropriate
for the `SimpleRequest.response_type`. If the server does not support the for the `SimpleRequest.response_type`. If the server does not support the
`response_type`, then it should fail the RPC with `INVALID_ARGUMENT`. `response_type`, then it should fail the RPC with `INVALID_ARGUMENT`.
### CacheableUnaryCall
Server gets the default Empty proto as the request. It returns the
SimpleResponse proto with the payload set to current timestamp string.
In addition it adds
1. cache control headers such that the response can be cached by proxies in
the response path. Server should be behind a caching proxy for this test
to pass.
2. adds a `x-user-ip` header with `1.2.3.4` to the response. This is done
since some proxys such as GFE will not cache requests from localhost.
### CompressedResponse ### CompressedResponse
[CompressedResponse]: #compressedresponse [CompressedResponse]: #compressedresponse
......
...@@ -848,10 +848,11 @@ bool InteropClient::DoStatusWithMessage() { ...@@ -848,10 +848,11 @@ bool InteropClient::DoStatusWithMessage() {
bool InteropClient::DoCacheableUnary() { bool InteropClient::DoCacheableUnary() {
gpr_log(GPR_DEBUG, "Sending RPC with cacheable response"); gpr_log(GPR_DEBUG, "Sending RPC with cacheable response");
// Create request with current timestamp
gpr_timespec ts = gpr_now(GPR_CLOCK_REALTIME);
std::string timestamp = std::to_string(ts.tv_nsec);
SimpleRequest request; SimpleRequest request;
request.set_response_size(16); request.mutable_payload()->set_body(timestamp.c_str(), timestamp.size());
grpc::string payload(16, '\0');
request.mutable_payload()->set_body(payload.c_str(), 16);
// Request 1 // Request 1
ClientContext context1; ClientContext context1;
...@@ -878,7 +879,7 @@ bool InteropClient::DoCacheableUnary() { ...@@ -878,7 +879,7 @@ bool InteropClient::DoCacheableUnary() {
if (!AssertStatusOk(s2)) { if (!AssertStatusOk(s2)) {
return false; return false;
} }
gpr_log(GPR_DEBUG, "response 1 payload: %s", gpr_log(GPR_DEBUG, "response 2 payload: %s",
response2.payload().body().c_str()); response2.payload().body().c_str());
// Check that the body is same for both requests. It will be the same if the // Check that the body is same for both requests. It will be the same if the
......
...@@ -159,7 +159,7 @@ class TestServiceImpl : public TestService::Service { ...@@ -159,7 +159,7 @@ class TestServiceImpl : public TestService::Service {
gpr_timespec ts = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec ts = gpr_now(GPR_CLOCK_REALTIME);
std::string timestamp = std::to_string(ts.tv_nsec); std::string timestamp = std::to_string(ts.tv_nsec);
response->mutable_payload()->set_body(timestamp.c_str(), timestamp.size()); response->mutable_payload()->set_body(timestamp.c_str(), timestamp.size());
context->AddInitialMetadata("Cache-Control", "max-age=100000, public"); context->AddInitialMetadata("cache-control", "max-age=100000, public");
return Status::OK; return Status::OK;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment