Skip to content

Commit

Permalink
Share runBlockingTest implementation in jvmAndNative
Browse files Browse the repository at this point in the history
  • Loading branch information
lauzadis committed Oct 17, 2023
1 parent 4360e79 commit 9083332
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,9 @@ package aws.smithy.kotlin.runtime.http.test.util

import aws.smithy.kotlin.runtime.http.engine.DefaultHttpEngine
import aws.smithy.kotlin.runtime.http.engine.crt.CrtHttpEngine
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import kotlin.coroutines.CoroutineContext
import kotlin.time.Duration

internal actual fun engineFactories(): List<TestEngineFactory> =
listOf(
TestEngineFactory("DefaultHttpEngine", ::DefaultHttpEngine),
TestEngineFactory("CrtHttpEngine") { CrtHttpEngine(it) },
)

internal actual fun runBlockingTest(
context: CoroutineContext,
timeout: Duration?,
block: suspend CoroutineScope.() -> Unit,
) {
runBlocking(context) {
if (timeout != null) {
withTimeout(timeout) {
block()
}
} else {
block()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package aws.smithy.kotlin.runtime.http.test.util

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import kotlin.coroutines.CoroutineContext
import kotlin.time.Duration

internal actual fun runBlockingTest(
context: CoroutineContext,
timeout: Duration?,
block: suspend CoroutineScope.() -> Unit,
) {
runBlocking(context) {
if (timeout != null) {
withTimeout(timeout) {
block()
}
} else {
block()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,4 @@ import kotlin.time.Duration

// FIXME add engines to test
internal actual fun engineFactories(): List<TestEngineFactory> =
listOf()

// FIXME duplicated from jvm source
internal actual fun runBlockingTest(
context: CoroutineContext,
timeout: Duration?,
block: suspend CoroutineScope.() -> Unit,
) {
runBlocking(context) {
if (timeout != null) {
withTimeout(timeout) {
block()
}
} else {
block()
}
}
}
listOf()

0 comments on commit 9083332

Please sign in to comment.