Skip to content

Commit ff6a786

Browse files
kggilmeraajtodd
andauthored
chore: coroutine version bump to 1.6.0 and Duration stabilization (#580)
* refactor tests to use `runTest` from `kotlinx-coroutines-test` * Duration API stabilization Co-authored-by: Aaron J Todd <[email protected]>
1 parent 6265f51 commit ff6a786

File tree

52 files changed

+283
-259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+283
-259
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ kotlinVersion=1.6.10
1212
dokkaVersion=1.6.10
1313

1414
# kotlin libraries
15-
coroutinesVersion=1.5.2
15+
coroutinesVersion=1.6.0
1616
ktorVersion=1.6.7
1717
atomicFuVersion=0.17.0
1818
kotlinxSerializationVersion=1.3.0

runtime/io/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ kotlin {
2424

2525
commonTest {
2626
dependencies {
27-
implementation(project(":runtime:testing"))
27+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion")
2828
}
2929
}
3030

runtime/io/common/test/aws/smithy/kotlin/runtime/io/SdkByteChannelOpsTest.kt

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55

66
package aws.smithy.kotlin.runtime.io
77

8-
import aws.smithy.kotlin.runtime.testing.runSuspendTest
8+
import kotlinx.coroutines.ExperimentalCoroutinesApi
99
import kotlinx.coroutines.launch
10+
import kotlinx.coroutines.test.runTest
1011
import kotlinx.coroutines.yield
11-
import kotlin.test.*
12-
12+
import kotlin.test.Test
13+
import kotlin.test.assertEquals
14+
import kotlin.test.assertFailsWith
15+
import kotlin.test.assertFalse
16+
import kotlin.test.assertNull
17+
import kotlin.test.assertTrue
18+
19+
@OptIn(ExperimentalCoroutinesApi::class)
1320
class SdkByteChannelOpsTest {
1421

1522
@Test
16-
fun testCopyTo() = runSuspendTest {
23+
fun testCopyTo() = runTest {
1724
val dst = SdkByteChannel(false)
1825

1926
val contents = byteArrayOf(1, 2, 3, 4, 5)
@@ -36,7 +43,7 @@ class SdkByteChannelOpsTest {
3643
}
3744

3845
@Test
39-
fun testCopyToFallback() = runSuspendTest {
46+
fun testCopyToFallback() = runTest {
4047
val dst = SdkByteChannel(false)
4148

4249
val contents = byteArrayOf(1, 2, 3, 4, 5)
@@ -60,7 +67,7 @@ class SdkByteChannelOpsTest {
6067
}
6168

6269
@Test
63-
fun testCopyToSameOrZero() = runSuspendTest {
70+
fun testCopyToSameOrZero() = runTest {
6471
val chan = SdkByteChannel(false)
6572
assertFailsWith<IllegalArgumentException> {
6673
chan.copyTo(chan)
@@ -70,7 +77,7 @@ class SdkByteChannelOpsTest {
7077
}
7178

7279
@Test
73-
fun testReadFromClosedChannel() = runSuspendTest {
80+
fun testReadFromClosedChannel() = runTest {
7481
val chan = SdkByteReadChannel(byteArrayOf(1, 2, 3, 4, 5))
7582
val buffer = ByteArray(3)
7683
var rc = chan.readAvailable(buffer)
@@ -82,7 +89,7 @@ class SdkByteChannelOpsTest {
8289
}
8390

8491
@Test
85-
fun testReadAvailableNoSuspend() = runSuspendTest {
92+
fun testReadAvailableNoSuspend() = runTest {
8693
val chan = SdkByteReadChannel("world!".encodeToByteArray())
8794
val buffer = SdkByteBuffer(16u)
8895
buffer.write("hello, ")
@@ -94,7 +101,7 @@ class SdkByteChannelOpsTest {
94101
}
95102

96103
@Test
97-
fun testReadAvailableSuspend() = runSuspendTest {
104+
fun testReadAvailableSuspend() = runTest {
98105
val chan = SdkByteChannel()
99106
val job = launch {
100107
val buffer = SdkByteBuffer(16u)
@@ -116,7 +123,7 @@ class SdkByteChannelOpsTest {
116123
}
117124

118125
@Test
119-
fun testAwaitContent() = runSuspendTest {
126+
fun testAwaitContent() = runTest {
120127
val chan = SdkByteChannel()
121128
var awaitingContent = false
122129
launch {
@@ -133,7 +140,7 @@ class SdkByteChannelOpsTest {
133140
}
134141

135142
@Test
136-
fun testReadUtf8Chars() = runSuspendTest {
143+
fun testReadUtf8Chars() = runTest {
137144
val chan = SdkByteReadChannel("hello".encodeToByteArray())
138145
assertEquals('h', chan.readUtf8CodePoint()?.toChar())
139146
assertEquals('e', chan.readUtf8CodePoint()?.toChar())
@@ -144,7 +151,7 @@ class SdkByteChannelOpsTest {
144151
}
145152

146153
@Test
147-
fun testReadMultibyteUtf8Chars(): Unit = runSuspendTest {
154+
fun testReadMultibyteUtf8Chars() = runTest {
148155
// https://www.fileformat.info/info/unicode/char/1d122/index.htm
149156
// $ - 1 byte, cent sign - 2bytes, euro sign - 3 bytes, musical clef - 4 points (surrogate pair)
150157
val content = "$¢€\uD834\uDD22"

runtime/io/common/test/aws/smithy/kotlin/runtime/io/SdkByteChannelSmokeTest.kt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44
*/
55
package aws.smithy.kotlin.runtime.io
66

7-
import aws.smithy.kotlin.runtime.testing.runSuspendTest
87
import io.kotest.matchers.string.shouldContain
98
import io.ktor.utils.io.core.*
10-
import kotlin.test.*
11-
9+
import kotlinx.coroutines.ExperimentalCoroutinesApi
10+
import kotlinx.coroutines.test.runTest
11+
import kotlin.test.Test
12+
import kotlin.test.assertEquals
13+
import kotlin.test.assertFails
14+
import kotlin.test.assertFalse
15+
import kotlin.test.assertTrue
16+
import kotlin.test.fail
17+
18+
@OptIn(ExperimentalCoroutinesApi::class)
1219
open class SdkByteChannelSmokeTest {
1320

1421
@Test
@@ -18,7 +25,7 @@ open class SdkByteChannelSmokeTest {
1825
}
1926

2027
@Test
21-
fun testAutoFlush() = runSuspendTest {
28+
fun testAutoFlush() = runTest {
2229
SdkByteChannel(false).use { chan ->
2330
assertFalse(chan.autoFlush)
2431
chan.writeByte(1)
@@ -39,7 +46,7 @@ open class SdkByteChannelSmokeTest {
3946
}
4047

4148
@Test
42-
fun testClose() = runSuspendTest {
49+
fun testClose() = runTest {
4350
val chan = SdkByteChannel(false)
4451
chan.writeByte(1)
4552
chan.writeByte(2)
@@ -68,7 +75,7 @@ open class SdkByteChannelSmokeTest {
6875
}
6976

7077
@Test
71-
fun testReadAndWriteFully() = runSuspendTest {
78+
fun testReadAndWriteFully() = runTest {
7279
val src = byteArrayOf(1, 2, 3, 4, 5)
7380
val sink = ByteArray(5)
7481
val chan = SdkByteChannel(false)
@@ -97,7 +104,7 @@ open class SdkByteChannelSmokeTest {
97104
}
98105

99106
@Test
100-
fun testReadAndWritePartial(): Unit = runSuspendTest {
107+
fun testReadAndWritePartial() = runTest {
101108
val src = byteArrayOf(1, 2, 3, 4, 5)
102109
val chan = SdkByteChannel(false)
103110
chan.writeFully(src)
@@ -117,7 +124,7 @@ open class SdkByteChannelSmokeTest {
117124
}
118125

119126
@Test
120-
fun testWriteString() = runSuspendTest {
127+
fun testWriteString() = runTest {
121128
val chan = SdkByteChannel(false)
122129
val content = "I meant what I said. And said what I meant. An elephant's faithful. One hundred percent!"
123130
chan.writeUtf8(content)
@@ -127,7 +134,7 @@ open class SdkByteChannelSmokeTest {
127134
}
128135

129136
@Test
130-
fun testReadChannelByteArrayCtor() = runSuspendTest {
137+
fun testReadChannelByteArrayCtor() = runTest {
131138
val src = byteArrayOf(1, 2, 3, 4, 5)
132139
val chan = SdkByteReadChannel(src)
133140
assertTrue(chan.isClosedForWrite)
@@ -147,7 +154,7 @@ open class SdkByteChannelSmokeTest {
147154
}
148155

149156
@Test
150-
fun testCloseableUse() = runSuspendTest {
157+
fun testCloseableUse() = runTest {
151158
val chan = SdkByteChannel(true)
152159
chan.writeFully(byteArrayOf(1, 2, 3, 4, 5))
153160
val rc = chan.use {

runtime/io/common/test/aws/smithy/kotlin/runtime/io/middleware/MiddlewareTest.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ package aws.smithy.kotlin.runtime.io.middleware
77

88
import aws.smithy.kotlin.runtime.io.Handler
99
import aws.smithy.kotlin.runtime.io.HandlerLambda
10-
import aws.smithy.kotlin.runtime.testing.runSuspendTest
10+
import kotlinx.coroutines.ExperimentalCoroutinesApi
11+
import kotlinx.coroutines.test.runTest
1112
import kotlin.test.Test
1213
import kotlin.test.assertEquals
1314

15+
@OptIn(ExperimentalCoroutinesApi::class)
1416
class MiddlewareTest {
1517

1618
@Test
17-
fun testDecorate() = runSuspendTest {
19+
fun testDecorate() = runTest {
1820
val handler = object : Handler<String, String> {
1921
override suspend fun call(request: String): String = request.replaceFirstChar { c -> c.uppercaseChar() }
2022
}
@@ -34,15 +36,15 @@ class MiddlewareTest {
3436
}
3537

3638
@Test
37-
fun testServiceLambda() = runSuspendTest {
39+
fun testServiceLambda() = runTest {
3840
val handler = HandlerLambda<String, String> {
3941
it.replaceFirstChar { c -> c.uppercaseChar() }
4042
}
4143
assertEquals("Foo", handler.call("foo"))
4244
}
4345

4446
@Test
45-
fun testMapRequest() = runSuspendTest {
47+
fun testMapRequest() = runTest {
4648
val handler = HandlerLambda<String, String> {
4749
it
4850
}
@@ -55,7 +57,7 @@ class MiddlewareTest {
5557
}
5658

5759
@Test
58-
fun testMapResponse() = runSuspendTest {
60+
fun testMapResponse() = runTest {
5961
val handler = HandlerLambda<String, String> {
6062
it
6163
}

runtime/io/common/test/aws/smithy/kotlin/runtime/io/middleware/PhaseTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
package aws.smithy.kotlin.runtime.io.middleware
77

88
import aws.smithy.kotlin.runtime.io.Handler
9-
import aws.smithy.kotlin.runtime.testing.runSuspendTest
9+
import kotlinx.coroutines.ExperimentalCoroutinesApi
10+
import kotlinx.coroutines.test.runTest
1011
import kotlin.test.Test
1112
import kotlin.test.assertEquals
1213

14+
@OptIn(ExperimentalCoroutinesApi::class)
1315
class PhaseTest {
1416
@Test
15-
fun `it orders interceptors`() = runSuspendTest {
17+
fun `it orders interceptors`() = runTest {
1618
val phase = Phase<String, String>()
1719
val order = mutableListOf<String>()
1820

runtime/protocol/http-client-engines/http-client-engine-ktor/jvm/src/aws/smithy/kotlin/runtime/http/engine/ktor/KtorEngine.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import okhttp3.ConnectionPool
2626
import okhttp3.Protocol
2727
import java.util.concurrent.TimeUnit
2828
import kotlin.coroutines.CoroutineContext
29-
import kotlin.time.ExperimentalTime
3029
import kotlin.time.toJavaDuration
3130
import aws.smithy.kotlin.runtime.http.response.HttpResponse as SdkHttpResponse
3231

@@ -36,14 +35,12 @@ import aws.smithy.kotlin.runtime.http.response.HttpResponse as SdkHttpResponse
3635
actual class KtorEngine actual constructor(
3736
config: HttpClientEngineConfig
3837
) : HttpClientEngineBase("ktor-okhttp") {
39-
4038
actual val config: HttpClientEngineConfig
4139

4240
init {
4341
this.config = config
4442
}
4543

46-
@OptIn(ExperimentalTime::class)
4744
val client: HttpClient = HttpClient(OkHttp) {
4845
engine {
4946
config {

runtime/protocol/http-client-engines/http-client-engine-ktor/jvm/test/aws/smithy/kotlin/runtime/http/engine/ktor/KtorEngineTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ package aws.smithy.kotlin.runtime.http.engine.ktor
88
import kotlinx.coroutines.ExperimentalCoroutinesApi
99
import kotlinx.coroutines.delay
1010
import kotlinx.coroutines.launch
11-
import kotlinx.coroutines.test.runBlockingTest
11+
import kotlinx.coroutines.test.currentTime
12+
import kotlinx.coroutines.test.runTest
1213
import kotlin.test.Test
1314
import kotlin.test.assertEquals
1415
import kotlin.time.Duration.Companion.milliseconds
@@ -17,7 +18,7 @@ import kotlin.time.ExperimentalTime
1718
@OptIn(ExperimentalCoroutinesApi::class, ExperimentalTime::class)
1819
class WaiterTest {
1920
@Test
20-
fun testSignalWhenWaiting() = runBlockingTest {
21+
fun testSignalWhenWaiting() = runTest {
2122
val start = currentTime
2223

2324
val waiter = Waiter()
@@ -31,7 +32,7 @@ class WaiterTest {
3132
}
3233

3334
@Test
34-
fun testSignalWhenNotWaiting() = runBlockingTest {
35+
fun testSignalWhenNotWaiting() = runTest {
3536
val start = currentTime
3637

3738
val waiter = Waiter()

runtime/protocol/http-test/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ description = "Utilities for testing HTTP requests"
66
extra["displayName"] = "Smithy :: Kotlin :: HTTP Test"
77
extra["moduleName"] = "aws.smithy.kotlin.runtime.httptest"
88

9+
val coroutinesVersion: String by project
910
val kotlinVersion: String by project
1011
val ktorVersion: String by project
1112
val kotlinxSerializationVersion: String by project
@@ -24,7 +25,7 @@ kotlin {
2425
}
2526
commonTest {
2627
dependencies {
27-
implementation(project(":runtime:testing"))
28+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion")
2829
}
2930
}
3031
jvmMain {

runtime/protocol/http-test/common/test/aws/smithy/kotlin/runtime/httptest/TestConnectionTest.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ import aws.smithy.kotlin.runtime.http.readAll
1111
import aws.smithy.kotlin.runtime.http.request.HttpRequestBuilder
1212
import aws.smithy.kotlin.runtime.http.response.complete
1313
import aws.smithy.kotlin.runtime.http.sdkHttpClient
14-
import aws.smithy.kotlin.runtime.testing.runSuspendTest
1514
import io.kotest.matchers.string.shouldContain
15+
import kotlinx.coroutines.ExperimentalCoroutinesApi
16+
import kotlinx.coroutines.test.runTest
1617
import kotlin.test.Test
1718
import kotlin.test.assertEquals
1819
import kotlin.test.assertFails
1920

21+
@OptIn(ExperimentalCoroutinesApi::class)
2022
class TestConnectionTest {
2123
@Test
22-
fun testAssertRequestsSuccess(): Unit = runSuspendTest {
24+
fun testAssertRequestsSuccess() = runTest {
2325
val engine = buildTestConnection {
2426
expect {
2527
request {
@@ -46,7 +48,7 @@ class TestConnectionTest {
4648
}
4749

4850
@Test
49-
fun testAssertRequestsUrlDifferent(): Unit = runSuspendTest {
51+
fun testAssertRequestsUrlDifferent() = runTest {
5052
val engine = buildTestConnection {
5153
expect {
5254
request {
@@ -73,7 +75,7 @@ class TestConnectionTest {
7375
}
7476

7577
@Test
76-
fun testAssertRequestsMissingHeader(): Unit = runSuspendTest {
78+
fun testAssertRequestsMissingHeader() = runTest {
7779
val engine = buildTestConnection {
7880
expect {
7981
request {
@@ -100,7 +102,7 @@ class TestConnectionTest {
100102
}
101103

102104
@Test
103-
fun testAssertRequestsBodyDifferent(): Unit = runSuspendTest {
105+
fun testAssertRequestsBodyDifferent() = runTest {
104106
val engine = buildTestConnection {
105107
expect {
106108
request {
@@ -128,7 +130,7 @@ class TestConnectionTest {
128130
}
129131

130132
@Test
131-
fun testAssertRequestsAny(): Unit = runSuspendTest {
133+
fun testAssertRequestsAny() = runTest {
132134
val engine = buildTestConnection {
133135
expect {
134136
request {
@@ -162,7 +164,7 @@ class TestConnectionTest {
162164
}
163165

164166
@Test
165-
fun testFromJson(): Unit = runSuspendTest {
167+
fun testFromJson() = runTest {
166168
// language=JSON
167169
val data = """
168170
[

0 commit comments

Comments
 (0)