Skip to content

Commit a87ffdf

Browse files
authored
Add ability to write integration-tests for servers (#4332)
## Motivation and Context This `integration-tests` directory makes it possible to write Rust code that you can run directly against the generated servers from the protocol test models. This makes it easier to test things like event streams behavior and other specifics that are hard to test with protocol tests alone. ## Description I added a test for #4325 (showing the broken behavior) that we can use when we fix this issue. This will also make it easy to test a number of other open issues that have been found. To make this easy I also added a `EventStreamSender::once` method for convenience. The `ManualEventStream` sender could be upstreamed at a later date so it is more broadly usable but I didn't want to pin down a public API for it right now. <!--- Describe your changes in detail --> ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 93ecc1f commit a87ffdf

File tree

12 files changed

+2495
-21
lines changed

12 files changed

+2495
-21
lines changed

codegen-core/common-test-models/rpcv2Cbor-extras.smithy

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,37 @@ service RpcV2CborService {
1515
ComplexStructOperation
1616
EmptyStructOperation
1717
SingleMemberStructOperation
18-
RecursiveUnionOperation
18+
RecursiveUnionOperation,
19+
StreamingOperation
1920
]
2021
}
2122

23+
operation StreamingOperation {
24+
input: StreamingOperationInput,
25+
output: StreamingOperationOutput,
26+
errors: [ValidationException]
27+
}
28+
29+
structure StreamingOperationOutput {
30+
events: Events
31+
}
32+
33+
structure StreamingOperationInput {
34+
events: Events
35+
}
36+
37+
38+
@streaming
39+
union Events {
40+
A: Event,
41+
B: Event,
42+
C: Event,
43+
}
44+
45+
structure Event {
46+
}
47+
48+
2249
// TODO(https://github.com/smithy-lang/smithy/issues/2326): Smithy should not
2350
// allow HTTP binding traits in this protocol.
2451
@http(uri: "/simple-struct-operation", method: "POST")
@@ -84,7 +111,6 @@ apply EmptyStructOperation @httpMalformedRequestTests([
84111
}
85112
}
86113
}
87-
88114
}
89115
])
90116

@@ -303,35 +329,26 @@ structure ErrorSerializationOperationOutput {
303329
structure SimpleStruct {
304330
blob: Blob
305331
boolean: Boolean
306-
307332
string: String
308-
309333
byte: Byte
310334
short: Short
311335
integer: Integer
312336
long: Long
313-
314337
float: Float
315338
double: Double
316-
317339
timestamp: Timestamp
318340
enum: Suit
319-
320341
// With `@required`.
321342

322343
@required requiredBlob: Blob
323344
@required requiredBoolean: Boolean
324-
325345
@required requiredString: String
326-
327346
@required requiredByte: Byte
328347
@required requiredShort: Short
329348
@required requiredInteger: Integer
330349
@required requiredLong: Long
331-
332350
@required requiredFloat: Float
333351
@required requiredDouble: Double
334-
335352
@required requiredTimestamp: Timestamp
336353
// @required requiredDocument: MyDocument
337354
@required requiredEnum: Suit
@@ -344,16 +361,14 @@ structure ComplexStruct {
344361
map: SimpleMap
345362
union: SimpleUnion
346363
unitUnion: UnitUnion
347-
348364
structureList: StructList
349-
350365
// `@required` for good measure here.
351366
@required complexList: ComplexList
352367
@required complexMap: ComplexMap
353368
@required complexUnion: ComplexUnion
354369
}
355370

356-
structure EmptyStruct { }
371+
structure EmptyStruct {}
357372

358373
structure SingleMemberStruct {
359374
message: String
@@ -399,7 +414,6 @@ map ComplexMap {
399414
union ComplexUnion {
400415
// Recursive path here.
401416
complexStruct: ComplexStruct
402-
403417
structure: SimpleStruct
404418
list: SimpleList
405419
map: SimpleMap

codegen-server-test/build.gradle.kts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,16 @@ smithy {
3535

3636
val allCodegenTests = "../codegen-core/common-test-models".let { commonModels ->
3737
listOf(
38-
CodegenTest("crate#Config", "naming_test_ops", imports = listOf("$commonModels/naming-obstacle-course-ops.smithy")),
39-
CodegenTest("casing#ACRONYMInside_Service", "naming_test_casing", imports = listOf("$commonModels/naming-obstacle-course-casing.smithy")),
38+
CodegenTest(
39+
"crate#Config",
40+
"naming_test_ops",
41+
imports = listOf("$commonModels/naming-obstacle-course-ops.smithy"),
42+
),
43+
CodegenTest(
44+
"casing#ACRONYMInside_Service",
45+
"naming_test_casing",
46+
imports = listOf("$commonModels/naming-obstacle-course-casing.smithy"),
47+
),
4048
CodegenTest(
4149
"naming_obs_structs#NamingObstacleCourseStructs",
4250
"naming_test_structs",
@@ -47,7 +55,7 @@ val allCodegenTests = "../codegen-core/common-test-models".let { commonModels ->
4755
CodegenTest(
4856
"smithy.protocoltests.rpcv2Cbor#RpcV2CborService",
4957
"rpcv2Cbor_extras",
50-
imports = listOf("$commonModels/rpcv2Cbor-extras.smithy")
58+
imports = listOf("$commonModels/rpcv2Cbor-extras.smithy"),
5159
),
5260
CodegenTest(
5361
"com.amazonaws.constraints#ConstraintsService",
@@ -110,6 +118,12 @@ tasks["assemble"].finalizedBy("generateCargoWorkspace", "generateCargoConfigToml
110118
project.registerModifyMtimeTask()
111119
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile)
112120

113-
tasks["test"].finalizedBy(cargoCommands(properties).map { it.toString })
121+
tasks.register<Exec>("cargoTestIntegration") {
122+
dependsOn("assemble")
123+
workingDir(projectDir.resolve("integration-tests"))
124+
commandLine("cargo", "test")
125+
}
126+
127+
tasks["test"].finalizedBy(cargoCommands(properties).map { it.toString }, "cargoTestIntegration")
114128

115129
tasks["clean"].doFirst { delete("smithy-build.json") }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cargo.lock

0 commit comments

Comments
 (0)