-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some additional E2E tests for client #147
Conversation
In several cases, we were not correctly calling callbacks when an exception occurred while reading a response body, parsing it using a Codec, or attempting to decompress it. Add some additional E2E tests in the new MockWebServerTests to exercise these failures and update the library code to handle the exceptions appropriately.
val responseCodec = serializationStrategy.codec(methodSpec.responseClass) | ||
val responseMessage: Output | ||
try { | ||
responseMessage = responseCodec.deserialize(finalResponse.message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were missing exception handling around deserializing using the Codec, which lead to not notifying callers of a failure.
@@ -95,13 +95,33 @@ internal class ConnectInterceptor( | |||
val responseHeaders = | |||
response.headers.filter { entry -> !entry.key.startsWith("trailer-") } | |||
val compressionPool = clientConfig.compressionPool(responseHeaders[CONTENT_ENCODING]?.first()) | |||
val responseBody = try { | |||
compressionPool?.decompress(response.message.buffer) ?: response.message.buffer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly we weren't handling exceptions properly when decompressing data.
val error = parseConnectUnaryException(code = response.code, response.headers, response.message.buffer) | ||
val error = parseConnectUnaryException(code = response.code, response.headers, responseBody) | ||
// We've already read the response body to parse an error - don't read again. | ||
message = Buffer() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erawhctim - This fixes the issue before where we'd both read a JSON error response and then read again for the message.
addHeader("accept-encoding", "gzip") | ||
addHeader("content-encoding", "gzip") | ||
setBody("this isn't gzipped") | ||
setResponseCode(200) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests http status = 200, invalid compressed data.
MockResponse().apply { | ||
addHeader("accept-encoding", "gzip") | ||
addHeader("content-type", "application/proto") | ||
setBody("this isn't valid protobuf") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests http status = 200, invalid proto message.
addHeader("accept-encoding", "gzip") | ||
addHeader("content-type", "application/json") | ||
setBody("{ invalid json") | ||
setResponseCode(200) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests http status = 200, invalid json message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good from my end; glad those extra error scenarios are under test now.
I was mostly debugging around in ConnectInterceptor
, and while the ProtocolClient
changes look reasonable to me, that part could use another set of eyes
In several cases, we were not correctly calling callbacks when an exception occurred while reading a response body, parsing it using a Codec, or attempting to decompress it. Add some additional E2E tests in the new MockWebServerTests to exercise these failures and update the library code to handle the exceptions appropriately.