Skip to content

Commit

Permalink
Reduce size of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Oct 24, 2023
1 parent 5cf82d2 commit 58b4ef1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class AtomicIntTest {

@Test
fun concurrentModifications() = runTestWithDelay {
val finalValue = 50_000
val finalValue = stackSafeIteration()
val r = AtomicInt(0)
(0 until finalValue).parMap { r.update { it + 1 } }
r.value shouldBe finalValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class AtomicLongTest {

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

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

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

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

fun runTestWithDelay(testBody: suspend () -> Unit): TestResult = runTest {
withContext(Dispatchers.Default) {
testBody()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import kotlinx.coroutines.test.runTest

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

@Test fun parMapOrAccumulateIsStackSafe() = runTestWithDelay {
val count = 20_000
val count = stackSafeIteration()
val ref = AtomicInt(0)
(0 until count).parMapOrAccumulate(combine = emptyError) { _: Int ->
ref.update { it + 1 }
Expand Down Expand Up @@ -145,14 +145,14 @@ class ParMapTest {

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

@Test fun parMapNotNullIsStackSafe() = runTestWithDelay {
val count = 20_000
val count = stackSafeIteration()
val ref = AtomicInt(0)
(0 until count).parMapNotNull { _: Int ->
ref.update { it + 1 }
Expand Down

0 comments on commit 58b4ef1

Please sign in to comment.