@@ -7,23 +7,18 @@ package aws.smithy.kotlin.runtime.http.test
77
88import aws.smithy.kotlin.runtime.content.ByteStream
99import aws.smithy.kotlin.runtime.hashing.sha256
10- import aws.smithy.kotlin.runtime.http.HttpBody
11- import aws.smithy.kotlin.runtime.http.HttpMethod
12- import aws.smithy.kotlin.runtime.http.HttpStatusCode
10+ import aws.smithy.kotlin.runtime.http.*
1311import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
1412import aws.smithy.kotlin.runtime.http.request.HttpRequest
1513import aws.smithy.kotlin.runtime.http.request.headers
1614import aws.smithy.kotlin.runtime.http.response.complete
1715import aws.smithy.kotlin.runtime.http.test.util.AbstractEngineTest
1816import aws.smithy.kotlin.runtime.http.test.util.test
1917import aws.smithy.kotlin.runtime.http.test.util.testSetup
20- import aws.smithy.kotlin.runtime.http.toHttpBody
2118import aws.smithy.kotlin.runtime.io.SdkByteChannel
2219import aws.smithy.kotlin.runtime.io.SdkByteReadChannel
2320import aws.smithy.kotlin.runtime.util.encodeToHex
24- import kotlinx.coroutines.coroutineScope
25- import kotlinx.coroutines.delay
26- import kotlinx.coroutines.launch
21+ import kotlinx.coroutines.*
2722import kotlin.test.Test
2823import kotlin.test.assertEquals
2924
@@ -84,6 +79,39 @@ class UploadTest : AbstractEngineTest() {
8479 }
8580 }
8681
82+ @Test
83+ fun testUploadWithClosingDelay () = testEngines {
84+ test { env, client ->
85+ val data = ByteArray (16 ) { it.toByte() }
86+ val sha = data.sha256().encodeToHex()
87+ val ch = SdkByteChannel (autoFlush = true )
88+ val content = object : HttpBody .Streaming () {
89+ override val contentLength: Long = data.size.toLong()
90+ override fun readFrom (): SdkByteReadChannel = ch
91+ }
92+
93+ val req = HttpRequest {
94+ method = HttpMethod .POST
95+ testSetup(env)
96+ url.path = " /upload/content"
97+ body = content
98+ }
99+
100+ coroutineScope {
101+ launch {
102+ ch.writeFully(data)
103+ delay(1000 )
104+ // CRT will have stopped polling by now
105+ ch.close()
106+ }
107+ val call = client.call(req)
108+ call.complete()
109+ assertEquals(HttpStatusCode .OK , call.response.status)
110+ assertEquals(sha, call.response.headers[" content-sha256" ])
111+ }
112+ }
113+ }
114+
87115 @Test
88116 fun testUploadWithWrappedStream () = testEngines {
89117 // test custom ByteStream behavior
0 commit comments