Skip to content

Commit

Permalink
Try again
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Oct 24, 2023
1 parent dcfb1f7 commit 5cf82d2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class AtomicIntTest {
}

@Test
fun concurrentModifications() = runBlockingOnNative {
fun concurrentModifications() = runTestWithDelay {
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
Expand Up @@ -97,7 +97,7 @@ class AtomicLongTest {
}

@Test
fun concurrentModifications() = runBlockingOnNative {
fun concurrentModifications() = runTestWithDelay {
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 @@ -101,7 +101,7 @@ class AtomicTest {
}

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

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.withTimeoutOrNull
import kotlinx.coroutines.test.runTest
import kotlin.test.Ignore

class ParMapTest {
@Test fun parMapIsStackSafe() = runBlockingOnNative {
@Test fun parMapIsStackSafe() = runTestWithDelay {
val count = 20_000
val ref = AtomicInt(0)
(0 until count).parMap { _: Int ->
Expand Down Expand Up @@ -89,7 +88,7 @@ class ParMapTest {
}
}

@Test fun parMapOrAccumulateIsStackSafe() = runBlockingOnNative {
@Test fun parMapOrAccumulateIsStackSafe() = runTestWithDelay {
val count = 20_000
val ref = AtomicInt(0)
(0 until count).parMapOrAccumulate(combine = emptyError) { _: Int ->
Expand Down Expand Up @@ -144,16 +143,15 @@ class ParMapTest {
} shouldBe null
}

@Test @Ignore
fun parMapOrAccumulateAccumulatesShifts() = runTest {
@Test fun parMapOrAccumulateAccumulatesShifts() = runTest {
checkAll(Arb.string()) { e ->
(0 until 100).parMapOrAccumulate { _ ->
raise(e)
} shouldBe NonEmptyList(e, (1 until 100).map { e }).left()
}
}

@Test fun parMapNotNullIsStackSafe() = runBlockingOnNative {
@Test fun parMapNotNullIsStackSafe() = runTestWithDelay {
val count = 20_000
val ref = AtomicInt(0)
(0 until count).parMapNotNull { _: Int ->
Expand Down Expand Up @@ -208,19 +206,17 @@ class ParMapTest {
} shouldBe null
}

@Test @Ignore
fun parMapNotNullDiscardsNulls() = runTest {
(0 until 100).parMapNotNull { _ ->
@Test fun parMapNotNullDiscardsNulls() = runTest {
(0 until 10).parMapNotNull { _ ->
null
} shouldBe emptyList()
}

@Test @Ignore
fun parMapNotNullRetainsNonNulls() = runTest {
@Test fun parMapNotNullRetainsNonNulls() = runTest {
checkAll(Arb.int()) { i ->
(0 until 100).parMapNotNull { _ ->
(0 until 10).parMapNotNull { _ ->
i
} shouldBe List(100) { i }
} shouldBe List(10) { i }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package arrow.fx.coroutines
import io.kotest.common.Platform
import io.kotest.common.platform
import io.kotest.common.runBlocking
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.TestResult
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.withContext

fun stackSafeIteration(): Int = when (platform) {
Platform.JVM -> 500_000
else -> 1000
}

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

0 comments on commit 5cf82d2

Please sign in to comment.