-
Notifications
You must be signed in to change notification settings - Fork 195
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
Server streaming body #1023
Server streaming body #1023
Changes from 4 commits
5ac9f1e
5b6ef98
f463cee
2ca7cc0
bfa1dee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ import software.amazon.smithy.rust.codegen.util.getTrait | |
import software.amazon.smithy.rust.codegen.util.hasStreamingMember | ||
import software.amazon.smithy.rust.codegen.util.hasTrait | ||
import software.amazon.smithy.rust.codegen.util.inputShape | ||
import software.amazon.smithy.rust.codegen.util.isStreaming | ||
import software.amazon.smithy.rust.codegen.util.orNull | ||
import software.amazon.smithy.rust.codegen.util.outputShape | ||
import software.amazon.smithy.rust.codegen.util.toSnakeCase | ||
|
@@ -212,16 +213,16 @@ class ServerProtocolTestGenerator( | |
|
||
rustTemplate( | ||
""" | ||
##[allow(unused_mut)] let mut http_request = http::Request::builder() | ||
.uri("${httpRequestTestCase.uri}") | ||
""", | ||
*codegenScope | ||
##[allow(unused_mut)] let mut http_request = http::Request::builder() | ||
.uri("${httpRequestTestCase.uri}") | ||
""", | ||
*codegenScope | ||
) | ||
for (header in httpRequestTestCase.headers) { | ||
rust(".header(${header.key.dq()}, ${header.value.dq()})") | ||
} | ||
rustTemplate( | ||
""" | ||
""" | ||
.body(#{SmithyHttpServer}::Body::from(#{Bytes}::from_static(b${httpRequestTestCase.body.orNull()?.dq()}))) | ||
.unwrap(); | ||
""", | ||
|
@@ -326,15 +327,37 @@ class ServerProtocolTestGenerator( | |
""" | ||
use #{AxumCore}::extract::FromRequest; | ||
let mut http_request = #{AxumCore}::extract::RequestParts::new(http_request); | ||
let input_wrapper = super::$operationName::from_request(&mut http_request).await.expect("failed to parse request"); | ||
let input = input_wrapper.0; | ||
let parsed = super::$operationName::from_request(&mut http_request).await.expect("failed to parse request").0; | ||
""", | ||
*codegenScope, | ||
) | ||
if (operationShape.outputShape(model).hasStreamingMember(model)) { | ||
rustWriter.rust("""todo!("streaming types aren't supported yet");""") | ||
|
||
if (inputShape.hasStreamingMember(model)) { | ||
// A streaming shape does not implement `PartialEq`, so we have to iterate over the input shape's members | ||
// and handle the equality assertion separately. | ||
for (member in inputShape.members()) { | ||
val memberName = codegenContext.symbolProvider.toMemberName(member) | ||
if (member.isStreaming(codegenContext.model)) { | ||
rustWriter.rustTemplate( | ||
""" | ||
#{AssertEq}( | ||
parsed.$memberName.collect().await.unwrap().into_bytes(), | ||
expected.$memberName.collect().await.unwrap().into_bytes() | ||
); | ||
""", | ||
*codegenScope | ||
) | ||
} else { | ||
rustWriter.rustTemplate( | ||
""" | ||
#{AssertEq}(parsed.$memberName, expected.$memberName, "Unexpected value for `$memberName`"); | ||
""", | ||
*codegenScope | ||
) | ||
} | ||
} | ||
} else { | ||
rustWriter.rustTemplate("#{AssertEq}(input, expected);", *codegenScope) | ||
rustWriter.rustTemplate("#{AssertEq}(parsed, expected);", *codegenScope) | ||
} | ||
} | ||
|
||
|
@@ -386,19 +409,19 @@ class ServerProtocolTestGenerator( | |
basicCheck( | ||
requireHeaders, | ||
rustWriter, | ||
"required_headers", | ||
actualExpression, | ||
"require_headers" | ||
"required_headers", | ||
actualExpression, | ||
"require_headers" | ||
) | ||
} | ||
|
||
private fun checkForbidHeaders(rustWriter: RustWriter, actualExpression: String, forbidHeaders: List<String>) { | ||
basicCheck( | ||
forbidHeaders, | ||
rustWriter, | ||
"forbidden_headers", | ||
"forbidden_headers", | ||
actualExpression, | ||
"forbid_headers" | ||
"forbid_headers" | ||
) | ||
} | ||
|
||
|
@@ -511,16 +534,11 @@ class ServerProtocolTestGenerator( | |
FailingTest(RestJson, "RestJsonNoInputAndNoOutput", Action.Response), | ||
FailingTest(RestJson, "RestJsonNoInputAndOutputWithJson", Action.Response), | ||
FailingTest(RestJson, "RestJsonSupportsNaNFloatInputs", Action.Request), | ||
FailingTest(RestJson, "RestJsonStreamingTraitsWithBlob", Action.Request), | ||
FailingTest(RestJson, "RestJsonStreamingTraitsWithNoBlobBody", Action.Request), | ||
FailingTest(RestJson, "RestJsonStreamingTraitsWithBlob", Action.Response), | ||
FailingTest(RestJson, "RestJsonStreamingTraitsWithNoBlobBody", Action.Response), | ||
FailingTest(RestJson, "RestJsonStreamingTraitsRequireLengthWithBlob", Action.Request), | ||
FailingTest(RestJson, "RestJsonStreamingTraitsRequireLengthWithNoBlobBody", Action.Request), | ||
FailingTest(RestJson, "RestJsonSupportsNaNFloatInputs", Action.Response), | ||
FailingTest(RestJson, "RestJsonSimpleScalarProperties", Action.Response), | ||
FailingTest(RestJson, "RestJsonSupportsInfinityFloatInputs", Action.Response), | ||
FailingTest(RestJson, "RestJsonSupportsNegativeInfinityFloatInputs", Action.Response), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @david-perez These seem to fail in CI - did I accidentally add these changes when rebasing from main? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, earlier today I had pushed to this branch a commit merging from But you didn't fetch it (?), and you force-pushed the latest commit. In general once a PR is open I think it's best to not rebase and force-push, only merge from main. Because AFAIK GitHub's UI won't show the previous history, only the rewrriten one, and that might confuse other people looking at the PR. The downside is that merging makes the history non-linear, but we always squash before merging, so I think it's a small price to pay for having an entire's PR history. Anyway, these tests can be removed from the failing list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it. thanks. pushed a commit to remove those. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's good now |
||
FailingTest(RestJson, "RestJsonStreamingTraitsRequireLengthWithBlob", Action.Response), | ||
FailingTest(RestJson, "RestJsonStreamingTraitsRequireLengthWithNoBlobBody", Action.Response), | ||
FailingTest(RestJson, "RestJsonStreamingTraitsWithMediaTypeWithBlob", Action.Request), | ||
FailingTest(RestJson, "RestJsonStreamingTraitsWithMediaTypeWithBlob", Action.Response), | ||
FailingTest(RestJson, "RestJsonHttpWithEmptyBlobPayload", Action.Request), | ||
FailingTest(RestJson, "RestJsonHttpWithEmptyStructurePayload", Action.Request), | ||
|
||
|
@@ -591,56 +609,64 @@ class ServerProtocolTestGenerator( | |
).asObjectNode().get() | ||
).build() | ||
private fun fixRestJsonAllQueryStringTypes(testCase: HttpRequestTestCase): HttpRequestTestCase = | ||
testCase.toBuilder().params( | ||
Node.parse("""{ | ||
"queryString": "Hello there", | ||
"queryStringList": ["a", "b", "c"], | ||
"queryStringSet": ["a", "b", "c"], | ||
"queryByte": 1, | ||
"queryShort": 2, | ||
"queryInteger": 3, | ||
"queryIntegerList": [1, 2, 3], | ||
"queryIntegerSet": [1, 2, 3], | ||
"queryLong": 4, | ||
"queryFloat": 1.1, | ||
"queryDouble": 1.1, | ||
"queryDoubleList": [1.1, 2.1, 3.1], | ||
"queryBoolean": true, | ||
"queryBooleanList": [true, false, true], | ||
"queryTimestamp": 1, | ||
"queryTimestampList": [1, 2, 3], | ||
"queryEnum": "Foo", | ||
"queryEnumList": ["Foo", "Baz", "Bar"], | ||
"queryParamsMapOfStringList": { | ||
"String": ["Hello there"], | ||
"StringList": ["a", "b", "c"], | ||
"StringSet": ["a", "b", "c"], | ||
"Byte": ["1"], | ||
"Short": ["2"], | ||
"Integer": ["3"], | ||
"IntegerList": ["1", "2", "3"], | ||
"IntegerSet": ["1", "2", "3"], | ||
"Long": ["4"], | ||
"Float": ["1.1"], | ||
"Double": ["1.1"], | ||
"DoubleList": ["1.1", "2.1", "3.1"], | ||
"Boolean": ["true"], | ||
"BooleanList": ["true", "false", "true"], | ||
"Timestamp": ["1970-01-01T00:00:01Z"], | ||
"TimestampList": ["1970-01-01T00:00:01Z", "1970-01-01T00:00:02Z", "1970-01-01T00:00:03Z"], | ||
"Enum": ["Foo"], | ||
"EnumList": ["Foo", "Baz", "Bar"] | ||
testCase.toBuilder().params( | ||
Node.parse( | ||
""" | ||
{ | ||
"queryString": "Hello there", | ||
"queryStringList": ["a", "b", "c"], | ||
"queryStringSet": ["a", "b", "c"], | ||
"queryByte": 1, | ||
"queryShort": 2, | ||
"queryInteger": 3, | ||
"queryIntegerList": [1, 2, 3], | ||
"queryIntegerSet": [1, 2, 3], | ||
"queryLong": 4, | ||
"queryFloat": 1.1, | ||
"queryDouble": 1.1, | ||
"queryDoubleList": [1.1, 2.1, 3.1], | ||
"queryBoolean": true, | ||
"queryBooleanList": [true, false, true], | ||
"queryTimestamp": 1, | ||
"queryTimestampList": [1, 2, 3], | ||
"queryEnum": "Foo", | ||
"queryEnumList": ["Foo", "Baz", "Bar"], | ||
"queryParamsMapOfStringList": { | ||
"String": ["Hello there"], | ||
"StringList": ["a", "b", "c"], | ||
"StringSet": ["a", "b", "c"], | ||
"Byte": ["1"], | ||
"Short": ["2"], | ||
"Integer": ["3"], | ||
"IntegerList": ["1", "2", "3"], | ||
"IntegerSet": ["1", "2", "3"], | ||
"Long": ["4"], | ||
"Float": ["1.1"], | ||
"Double": ["1.1"], | ||
"DoubleList": ["1.1", "2.1", "3.1"], | ||
"Boolean": ["true"], | ||
"BooleanList": ["true", "false", "true"], | ||
"Timestamp": ["1970-01-01T00:00:01Z"], | ||
"TimestampList": ["1970-01-01T00:00:01Z", "1970-01-01T00:00:02Z", "1970-01-01T00:00:03Z"], | ||
"Enum": ["Foo"], | ||
"EnumList": ["Foo", "Baz", "Bar"] | ||
} | ||
} | ||
}""".trimMargin()).asObjectNode().get() | ||
).build() | ||
""".trimMargin() | ||
).asObjectNode().get() | ||
).build() | ||
private fun fixRestJsonQueryStringEscaping(testCase: HttpRequestTestCase): HttpRequestTestCase = | ||
testCase.toBuilder().params( | ||
Node.parse("""{ | ||
"queryString": "%:/?#[]@!${'$'}&'()*+,;=😹", | ||
"queryParamsMapOfStringList": { | ||
"String": ["%:/?#[]@!${'$'}&'()*+,;=😹"] | ||
} | ||
}""".trimMargin()).asObjectNode().get() | ||
Node.parse( | ||
""" | ||
{ | ||
"queryString": "%:/?#[]@!${'$'}&'()*+,;=😹", | ||
"queryParamsMapOfStringList": { | ||
"String": ["%:/?#[]@!${'$'}&'()*+,;=😹"] | ||
} | ||
} | ||
""".trimMargin() | ||
).asObjectNode().get() | ||
).build() | ||
// This test assumes that errors in responses are identified by an `X-Amzn-Errortype` header with the error shape name. | ||
// However, Smithy specifications for AWS protocols that serialize to JSON recommend that new server implementations | ||
|
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.
@david-perez @crisidev I was not sure what to do here - should I remove these tests from the expect-fail list as these now seem to pass...?
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.
Yep, if it passes it can be removed from the failing list.
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.
@guymguym I manually verified the now-passing tests and they look good.
I also had a look at the remaining failing request streaming protocol tests and pushed a new commit to this branch, Add blob streaming support for server request protocol tests, to get rid of them.
The only remaining failing protocol test for streaming is
RestJsonStreamingTraitsRequireLengthWithBlob
, but that is due to us not settingContent-Length
appropriately, so I've cut #1146 to track that.Let me know if you agree with the fix or have any questions.
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.
That's great @david-perez. Thank you for making it so easy!