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

fix(rt): emulate a real response body more closely to help catch subtle codegen bugs #505

Merged
merged 2 commits into from
Oct 21, 2021

Conversation

aajtodd
Copy link
Contributor

@aajtodd aajtodd commented Oct 20, 2021

Issue #

sibling PR: awslabs/aws-sdk-kotlin#358

Description of changes

Use a streaming single use HttpBody variant for protocol tests which will more closely reflect reality.

Scope

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

// emulate a real response stream which typically can only be consumed once
// see: https://github.com/awslabs/aws-sdk-kotlin/issues/356
object : HttpBody.Streaming() {
private var cnt = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

a boolean would suffice here but it hardly matters in a unit test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh it matters! (/s) I had a different version with count because I was getting weird results (turned out to be user error). I'll circle back and update/simplify.

Comment on lines 90 to 101
val body: HttpBody = testBuilder.expected.body?.let {
ByteArrayContent(it.encodeToByteArray())
// emulate a real response stream which typically can only be consumed once
// see: https://github.com/awslabs/aws-sdk-kotlin/issues/356
object : HttpBody.Streaming() {
private var consumed = false
override fun readFrom(): SdkByteReadChannel {
val content = if (consumed) ByteArray(0) else it.encodeToByteArray()
consumed = true
return SdkByteReadChannel(content)
}
}
} ?: HttpBody.Empty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: While I recognize that we were missing how consume-once streams were handled before, it seems like we'll now miss how replayable streams and simple byte arrays are handled. Is there value in testing both cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Response bodies are always going to be a single use stream. At least starting from the engine. What happens in middleware may change this (as we do with wrapped response).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I was confusing this with requests. Never mind then.

@aajtodd aajtodd merged commit f949a4b into main Oct 21, 2021
@aajtodd aajtodd deleted the fix-error-codegen branch October 21, 2021 12:34
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