Skip to content
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

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

pkwarren
Copy link
Contributor

@pkwarren pkwarren commented Nov 8, 2023

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.

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)
Copy link
Contributor Author

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
Copy link
Contributor Author

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()
Copy link
Contributor Author

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)
Copy link
Contributor Author

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")
Copy link
Contributor Author

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)
Copy link
Contributor Author

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.

Copy link
Contributor

@erawhctim erawhctim left a 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

@pkwarren pkwarren merged commit 1693395 into main Nov 9, 2023
7 checks passed
@pkwarren pkwarren deleted the pkw/add-additional-e2e-failures branch November 9, 2023 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants