Skip to content

Commit

Permalink
Use runBlocking on Native
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Oct 24, 2023
1 parent 45b387b commit 886704c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package arrow.atomic

import arrow.fx.coroutines.parMap
import io.kotest.common.runBlocking
import kotlin.test.Test
import kotlinx.coroutines.test.runTest
import io.kotest.matchers.shouldBe
Expand Down Expand Up @@ -97,7 +98,7 @@ class AtomicIntTest {
}

@Test
fun concurrentModifications() = runTest {
fun concurrentModifications() = runBlockingOnNative {
val finalValue = 50_000
val r = AtomicInt(0)
(0 until finalValue).parMap { r.update { it + 1 } }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package arrow.atomic

import arrow.fx.coroutines.parMap
import io.kotest.common.runBlocking
import kotlin.test.Test
import kotlinx.coroutines.test.runTest
import io.kotest.matchers.shouldBe
Expand Down Expand Up @@ -97,7 +98,7 @@ class AtomicLongTest {
}

@Test
fun concurrentModifications() = runTest {
fun concurrentModifications() = runBlockingOnNative {
val finalValue = 50_000
val r = AtomicLong(0)
(0 until finalValue).parMap { r.update { it + 1 } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ class AtomicTest {
}

@Test
fun concurrentModifications() = runBlocking {
fun concurrentModifications() = runBlockingOnNative {
val finalValue = 50_000
val r = Atomic("")
(0 until finalValue).parMap { r.update { it + "a" } }
r.value shouldBe "a".repeat(finalValue)
Unit
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package arrow.atomic

import io.kotest.common.runBlocking
import kotlinx.coroutines.test.runTest
import io.kotest.common.Platform
import io.kotest.common.platform

fun runBlockingOnNative(testBody: suspend () -> Unit) {
if (platform == Platform.Native)
runBlocking(testBody)
else
runTest { testBody() }
}

0 comments on commit 886704c

Please sign in to comment.