Skip to content

Commit

Permalink
Run ktor-client tests only on JVM
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Feb 4, 2025
1 parent fb1dd18 commit 600f382
Showing 1 changed file with 5 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ import io.ktor.server.routing.RoutingContext
import io.ktor.server.routing.get
import io.ktor.server.testing.ApplicationTestBuilder
import io.ktor.server.testing.testApplication
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.TestResult
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.withContext
import kotlin.test.Test
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

class HttpRequestScheduleTest {

Expand All @@ -45,9 +39,9 @@ class HttpRequestScheduleTest {
configure: HttpRequestSchedule.Configuration.() -> Unit
): HttpClient = createClient { install(HttpRequestSchedule, configure) }

val MAX_CHECKS = 10L
val MAX_CHECKS = 19L

@Test fun recurs() = runTestUsingDefaultDispatcher {
@Test fun recurs() = runTest {
checkAll(Arb.long(0, MAX_CHECKS)) { l ->
testApplication {
val counter = configureServer { }
Expand All @@ -63,7 +57,7 @@ class HttpRequestScheduleTest {
}
}

@Test fun doWhile() = runTestUsingDefaultDispatcher {
@Test fun doWhile() = runTest {
checkAll(Arb.long(0, MAX_CHECKS)) { l ->
testApplication {
val counter = configureServer { c ->
Expand All @@ -83,7 +77,7 @@ class HttpRequestScheduleTest {

class NetworkError : Throwable()

@Test fun retry() = runTestUsingDefaultDispatcher {
@Test fun retry() = runTest {
checkAll(Arb.long(0, MAX_CHECKS)) { l ->
testApplication {
val counter = configureServer { c ->
Expand All @@ -101,7 +95,7 @@ class HttpRequestScheduleTest {
}
}

@Test fun schedule() = runTestUsingDefaultDispatcher {
@Test fun schedule() = runTest {
checkAll(Arb.long(1, MAX_CHECKS)) { l ->
testApplication {
val counter = configureServer { c ->
Expand All @@ -125,15 +119,3 @@ class HttpRequestScheduleTest {
}
}
}

// The normal dispatcher with 'runTest' does some magic
// which doesn't go well in some platforms
fun runTestUsingDefaultDispatcher(
timeout: Duration = 40.seconds,
testBody: suspend TestScope.() -> Unit
): TestResult = runTest(timeout = timeout) {
withContext(Dispatchers.Default) {
testBody()
}
}

0 comments on commit 600f382

Please sign in to comment.