diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/BracketCaseTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/BracketCaseTest.kt index 62cd84c51b..b5a881959a 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/BracketCaseTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/BracketCaseTest.kt @@ -19,7 +19,7 @@ import kotlin.time.ExperimentalTime class BracketCaseTest { @Test fun immediateAcquireBracketCaseFinishesSuccessfully() = runTest { - checkAll(Arb.int(), Arb.int()) { a, b -> + checkAll(10, Arb.int(), Arb.int()) { a, b -> var once = true bracketCase( acquire = { a }, @@ -34,7 +34,7 @@ class BracketCaseTest { @Test fun suspendedAcquireBracketCaseFinishedSuccessfully() = runTest { - checkAll(Arb.int(), Arb.int()) { a, b -> + checkAll(10, Arb.int(), Arb.int()) { a, b -> var once = true bracketCase( acquire = { a.suspend() }, @@ -49,7 +49,7 @@ class BracketCaseTest { @Test fun immediateErrorInAcquireStaysTheSameError() = runTest { - checkAll(Arb.throwable()) { e -> + checkAll(10, Arb.throwable()) { e -> Either.catch { bracketCase( acquire = { throw e }, @@ -62,7 +62,7 @@ class BracketCaseTest { @Test fun suspendErrorInAcquireStaysTheSameError() = runTest { - checkAll(Arb.throwable()) { e -> + checkAll(10, Arb.throwable()) { e -> Either.catch { bracketCase( acquire = { e.suspend() }, @@ -75,7 +75,7 @@ class BracketCaseTest { @Test fun immediateUseBracketCaseFinishedSuccessfully() = runTest { - checkAll(Arb.int(), Arb.int()) { a, b -> + checkAll(10, Arb.int(), Arb.int()) { a, b -> var once = true bracketCase( acquire = { a }, @@ -90,7 +90,7 @@ class BracketCaseTest { @Test fun suspendedUseBracketCaseFinishesSuccessfully() = runTest { - checkAll(Arb.int(), Arb.int()) { a, b -> + checkAll(10, Arb.int(), Arb.int()) { a, b -> var once = true bracketCase( acquire = { a }, @@ -105,7 +105,7 @@ class BracketCaseTest { @Test fun bracketCaseMustRunReleaseTaskOnUseImmediateError() = runTest { - checkAll(Arb.int(), Arb.throwable()) { i, e -> + checkAll(10, Arb.int(), Arb.throwable()) { i, e -> val promise = CompletableDeferred() Either.catch { @@ -124,7 +124,7 @@ class BracketCaseTest { @Test fun bracketCaseMustRunReleaseTaskOnUseSuspendedError() = runTest { - checkAll(Arb.int(), Arb.throwable()) { x, e -> + checkAll(10, Arb.int(), Arb.throwable()) { x, e -> val promise = CompletableDeferred>() Either.catch { @@ -143,7 +143,7 @@ class BracketCaseTest { @Test fun bracketCaseMustAlwaysRunImmediateRelease() = runTest { - checkAll(Arb.int()) { x -> + checkAll(10, Arb.int()) { x -> val promise = CompletableDeferred>() Either.catch { @@ -162,7 +162,7 @@ class BracketCaseTest { @Test fun bracketCaseMustAlwaysRunSuspendedRelease() = runTest { - checkAll(Arb.int()) { x -> + checkAll(10, Arb.int()) { x -> val promise = CompletableDeferred>() Either.catch { @@ -182,7 +182,7 @@ class BracketCaseTest { @Test fun bracketCaseMustAlwaysRunImmediateReleaseError() = runTest { - checkAll(Arb.int(), Arb.throwable()) { n, e -> + checkAll(10, Arb.int(), Arb.throwable()) { n, e -> Either.catch { bracketCase( acquire = { n }, @@ -195,7 +195,7 @@ class BracketCaseTest { @Test fun bracketCaseMustAlwaysRunSuspendedReleaseError() = runTest { - checkAll(Arb.int(), Arb.throwable()) { n, e -> + checkAll(10, Arb.int(), Arb.throwable()) { n, e -> Either.catch { bracketCase( acquire = { n }, @@ -211,7 +211,7 @@ class BracketCaseTest { @Test fun bracketCaseMustComposeImmediateUseAndImmediateReleaseError() = runTest { - checkAll(Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> + checkAll(10, Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> Either.catch { bracketCase( acquire = { n }, @@ -224,7 +224,7 @@ class BracketCaseTest { @Test fun bracketCaseMustComposeSuspendUseAndImmediateReleaseError() = runTest { - checkAll(Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> + checkAll(10, Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> Either.catch { bracketCase( acquire = { n }, @@ -237,7 +237,7 @@ class BracketCaseTest { @Test fun bracketCaseMustComposeImmediateUseAndSuspendReleaseError() = runTest { - checkAll(Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> + checkAll(10, Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> Either.catch { bracketCase( acquire = { n }, @@ -250,7 +250,7 @@ class BracketCaseTest { @Test fun bracketCaseMustComposeSuspendUseAndSuspendReleaseError() = runTest { - checkAll(Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> + checkAll(10, Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> Either.catch { bracketCase( acquire = { n }, @@ -338,7 +338,7 @@ class BracketCaseTest { @Test fun acquireOnBracketCaseIsNotCancellable() = runTest { - checkAll(Arb.int(), Arb.int()) { x, y -> + checkAll(10, Arb.int(), Arb.int()) { x, y -> val mVar = Channel(1).apply { send(x) } val latch = CompletableDeferred() val p = CompletableDeferred() @@ -367,7 +367,7 @@ class BracketCaseTest { @Test fun releaseOnBracketCaseIsNotCancellable() = runTest { - checkAll(Arb.int(), Arb.int()) { x, y -> + checkAll(10, Arb.int(), Arb.int()) { x, y -> val mVar = Channel(1).apply { send(x) } val latch = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CountDownLatchSpec.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CountDownLatchSpec.kt index 738c48ffdb..fbaf381625 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CountDownLatchSpec.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CountDownLatchSpec.kt @@ -19,7 +19,7 @@ import kotlin.test.Test class CountDownLatchSpec { @Test fun shouldRaiseAnExceptionWhenConstructedWithNegativeOrZeroCapacity() = runTest { - checkAll(Arb.long(Long.MIN_VALUE, 0)) { i -> + checkAll(10, Arb.long(Long.MIN_VALUE, 0)) { i -> shouldThrow { CountDownLatch(i) }.message shouldBe "CountDownLatch must be constructed with positive non-zero initial count, but was $i" } @@ -27,7 +27,7 @@ class CountDownLatchSpec { @Test fun releaseAndThenAwaitShouldComplete() = runTest { - checkAll(Arb.long(1, 20)) { count -> + checkAll(10, Arb.long(1, 20)) { count -> val latch = CountDownLatch(count) repeat(count.toInt()) { latch.countDown() } latch.await() shouldBe Unit @@ -36,7 +36,7 @@ class CountDownLatchSpec { @Test fun awaitAndThenReleaseShouldComplete() = runTest { - checkAll(Arb.long(1, 20)) { count -> + checkAll(10, Arb.long(1, 20)) { count -> val latch = CountDownLatch(count) val job = launch { latch.await() } repeat(count.toInt()) { latch.countDown() } @@ -46,7 +46,7 @@ class CountDownLatchSpec { @Test fun awaitWithMoreThanOneLatchUnreleasedShouldBlock() = runTest { - checkAll(Arb.long(1, 20)) { count -> + checkAll(10, Arb.long(1, 20)) { count -> val latch = CountDownLatch(count) repeat(count.toInt() - 1) { latch.countDown() } withTimeoutOrNull(1) { latch.await() }.shouldBeNull() @@ -56,7 +56,7 @@ class CountDownLatchSpec { @Test fun multipleAwaitsShouldAllComplete() = runTest { - checkAll(Arb.long(1, 20)) { count -> + checkAll(10, Arb.long(1, 20)) { count -> val latch = CountDownLatch(count) val jobs = (0 until count).map { launch { latch.await() } } repeat(count.toInt()) { latch.countDown() } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt index c678fa690e..52423e8b06 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt @@ -18,7 +18,7 @@ import kotlin.test.Test class CyclicBarrierSpec { @Test fun shouldRaiseAnExceptionWhenConstructedWithNegativeOrZeroCapacity() = runTest { - checkAll(Arb.int(Int.MIN_VALUE, 0)) { i -> + checkAll(10, Arb.int(Int.MIN_VALUE, 0)) { i -> shouldThrow { CyclicBarrier(i) }.message shouldBe "Cyclic barrier must be constructed with positive non-zero capacity $i but was $i > 0" } @@ -26,7 +26,7 @@ class CyclicBarrierSpec { @Test fun barrierOfCapacity1IsANoOp() = runTest { - checkAll(Arb.constant(Unit)) { + checkAll(10, Arb.constant(Unit)) { val barrier = CyclicBarrier(1) barrier.await() } @@ -34,7 +34,7 @@ class CyclicBarrierSpec { @Test fun awaitingAllInParallelResumesAllCoroutines() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(1, 20)) { i -> + checkAll(10, Arb.int(1, 20)) { i -> val barrier = CyclicBarrier(i) (0 until i).parMap { barrier.await() } } @@ -42,7 +42,7 @@ class CyclicBarrierSpec { @Test fun shouldResetOnceFull() = runTestUsingDefaultDispatcher { - checkAll(Arb.constant(Unit)) { + checkAll(10, Arb.constant(Unit)) { val barrier = CyclicBarrier(2) parZip({ barrier.await() }, { barrier.await() }) { _, _ -> } barrier.capacity shouldBe 2 @@ -60,7 +60,7 @@ class CyclicBarrierSpec { @Test fun awaitIsCancelable() = runTest { - checkAll(Arb.int(2, Int.MAX_VALUE)) { i -> + checkAll(10, Arb.int(2, Int.MAX_VALUE)) { i -> val barrier = CyclicBarrier(i) val exitCase = CompletableDeferred() @@ -77,7 +77,7 @@ class CyclicBarrierSpec { @Test fun shouldCleanUpUponCancellationOfAwait() = runTest { - checkAll(Arb.constant(Unit)) { + checkAll(10, Arb.constant(Unit)) { val barrier = CyclicBarrier(2) launch(start = CoroutineStart.UNDISPATCHED) { barrier.await() }.cancelAndJoin() } @@ -85,7 +85,7 @@ class CyclicBarrierSpec { @Test fun resetCancelsAllAwaiting() = runTest { - checkAll(Arb.int(2, 20)) { i -> + checkAll(10, Arb.int(2, 20)) { i -> val barrier = CyclicBarrier(i) val exitCase = CompletableDeferred() @@ -103,7 +103,7 @@ class CyclicBarrierSpec { @Test fun shouldCleanUpUponReset() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(2, 20)) { i -> + checkAll(10, Arb.int(2, 20)) { i -> val barrier = CyclicBarrier(i) val exitCase = CompletableDeferred() @@ -119,7 +119,7 @@ class CyclicBarrierSpec { @Test fun raceFiberCancelAndBarrierFull() = runTestUsingDefaultDispatcher { - checkAll(Arb.constant(Unit)) { + checkAll(10, Arb.constant(Unit)) { val barrier = CyclicBarrier(2) val job = launch(start = CoroutineStart.UNDISPATCHED) { barrier.await() } when (raceN({ barrier.await() }, { job.cancelAndJoin() })) { @@ -133,7 +133,7 @@ class CyclicBarrierSpec { @Test fun reset() = runTest { - checkAll(Arb.int(2..10)) { n -> + checkAll(10, Arb.int(2..10)) { n -> val barrier = CyclicBarrier(n) val exits = (0 until n - 1).map { CompletableDeferred() } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt index 8c4f3baf50..0d921360f0 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt @@ -36,7 +36,7 @@ class FlowTest { @Test fun parMapConcurrentEqualOneMinusIdentity() = runTestUsingDefaultDispatcher { - checkAll(Arb.flow(Arb.int(), range = 1 .. 20)) { flow -> + checkAll(10, Arb.flow(Arb.int(), range = 1 .. 20)) { flow -> flow.parMap(1) { it } .toList() shouldBe flow.toList() } @@ -44,7 +44,7 @@ class FlowTest { @Test fun parMapRunsInParallel() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int(1..2)) { i, n -> + checkAll(10, Arb.int(), Arb.int(1..2)) { i, n -> val latch = CompletableDeferred() flowOf(1, 2).parMap { index -> if (index == n) latch.await() @@ -77,7 +77,7 @@ class FlowTest { @Test fun parMapExceptionInParMapCancelsAllRunningTasks() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.throwable(), Arb.int(1..2)) { i, e, n -> + checkAll(10, Arb.int(), Arb.throwable(), Arb.int(1..2)) { i, e, n -> val latch = CompletableDeferred() val exit = CompletableDeferred>() @@ -104,7 +104,7 @@ class FlowTest { @Test fun parMapCancellingParMapCancelsAllRunningJobs() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int()) { i, i2 -> + checkAll(10, Arb.int(), Arb.int()) { i, i2 -> val latch = CompletableDeferred() val exitA = CompletableDeferred>() val exitB = CompletableDeferred>() @@ -136,7 +136,7 @@ class FlowTest { @Test fun parMapUnorderedConcurrentEqualOneMinusIdentity() = runTestUsingDefaultDispatcher { - checkAll(Arb.flow(Arb.int(), range = 1 .. 20)) { flow -> + checkAll(10, Arb.flow(Arb.int(), range = 1 .. 20)) { flow -> flow.parMapUnordered(concurrency = 1) { it } .toSet() shouldBe flow.toSet() } @@ -144,7 +144,7 @@ class FlowTest { @Test fun parMapUnorderedRunsInParallel() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int(1..2)) { i, n -> + checkAll(10, Arb.int(), Arb.int(1..2)) { i, n -> val latch = CompletableDeferred() flowOf(1, 2).parMapUnordered { index -> if (index == n) latch.await() @@ -178,7 +178,7 @@ class FlowTest { @Test fun parMapUnorderedExceptionInParMapCancelsAllRunningTasks() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.throwable(), Arb.int(1..2)) { i, e, n -> + checkAll(10, Arb.int(), Arb.throwable(), Arb.int(1..2)) { i, e, n -> val latch = CompletableDeferred() val exit = CompletableDeferred>() @@ -205,7 +205,7 @@ class FlowTest { @Test fun parMapUnorderedCancellingParMapCancelsAllRunningJobs() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int()) { i, i2 -> + checkAll(10, Arb.int(), Arb.int()) { i, i2 -> val latch = CompletableDeferred() val exitA = CompletableDeferred>() val exitB = CompletableDeferred>() @@ -255,7 +255,7 @@ class FlowTest { @Test @ExperimentalTime fun fixedDelay() = runTest { - checkAll(Arb.long(10L .. 50L), Arb.int(3..20)) { waitPeriodInMillis, n -> + checkAll(10, Arb.long(10L .. 50L), Arb.int(3..20)) { waitPeriodInMillis, n -> val waitPeriod = waitPeriodInMillis.milliseconds val emissionDuration = (waitPeriodInMillis / 10L).milliseconds var state: ComparableTimeMark? = null @@ -281,7 +281,7 @@ class FlowTest { @Test @ExperimentalTime fun fixedRate() = runTest { - checkAll(Arb.long(10L..50L), Arb.int(3..20)) { waitPeriodInMillis, n -> + checkAll(10, Arb.long(10L..50L), Arb.int(3..20)) { waitPeriodInMillis, n -> val waitPeriod = waitPeriodInMillis.milliseconds val emissionDuration = (waitPeriodInMillis / 10L).milliseconds var state: ComparableTimeMark? = null diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/GuaranteeCaseTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/GuaranteeCaseTest.kt index 1795c98fc0..0f7df1bf6e 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/GuaranteeCaseTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/GuaranteeCaseTest.kt @@ -16,7 +16,7 @@ class GuaranteeCaseTest { @Test fun releaseForSuccessWasInvoked() = runTest { - checkAll(Arb.int()) { i -> + checkAll(10, Arb.int()) { i -> val p = CompletableDeferred() val res = guaranteeCase( @@ -31,7 +31,7 @@ class GuaranteeCaseTest { @Test fun releaseForErrorWasInvoked() = runTest { - checkAll(Arb.throwable()) { e -> + checkAll(10, Arb.throwable()) { e -> val p = CompletableDeferred() val attempted = Either.catch { guaranteeCase( diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParMapTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParMapTest.kt index 5a925875cd..ead4d9c4bb 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParMapTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParMapTest.kt @@ -144,7 +144,7 @@ class ParMapTest { } @Test fun parMapOrAccumulateAccumulatesShifts() = runTestUsingDefaultDispatcher { - checkAll(Arb.string()) { e -> + checkAll(10, Arb.string()) { e -> (0 until 10).parMapOrAccumulate { _ -> raise(e) } shouldBe NonEmptyList(e, (1 until 10).map { e }).left() @@ -213,7 +213,7 @@ class ParMapTest { } @Test fun parMapNotNullRetainsNonNulls() = runTestUsingDefaultDispatcher { - checkAll(Arb.int()) { i -> + checkAll(10, Arb.int()) { i -> (0 until 10).parMapNotNull { _ -> i } shouldBe List(10) { i } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip2Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip2Test.kt index 86bd3478d4..a1f8e77fdd 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip2Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip2Test.kt @@ -22,7 +22,7 @@ import kotlin.test.Test class ParZip2Test { @Test fun parZip2RunsInParallel() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int()) { a, b -> + checkAll(10, Arb.int(), Arb.int()) { a, b -> val r = AtomicInt(0) val modifyGate = CompletableDeferred() @@ -44,7 +44,7 @@ class ParZip2Test { } @Test fun cancellingParZip2CancelsAllParticipants() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int()) { a, b -> + checkAll(10, Arb.int(), Arb.int()) { a, b -> val s = Channel() val pa = CompletableDeferred>() val pb = CompletableDeferred>() @@ -72,7 +72,7 @@ class ParZip2Test { } @Test fun parZip2CancelsLosersIfAFailtureOccursInOneOfTheTasts() = runTestUsingDefaultDispatcher { - checkAll(Arb.throwable(), Arb.boolean()) { e, leftWinner -> + checkAll(10, Arb.throwable(), Arb.boolean()) { e, leftWinner -> val s = Channel() val pa = CompletableDeferred() @@ -91,7 +91,7 @@ class ParZip2Test { } @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { - checkAll(Arb.string()) { msg -> + checkAll(10, Arb.string()) { msg -> val exit = CompletableDeferred() val start = CompletableDeferred() try { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip3Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip3Test.kt index bf10afad39..c84812ebfa 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip3Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip3Test.kt @@ -21,7 +21,7 @@ import kotlin.test.Test class ParZip3Test { @Test fun parZip3RunsInParallel() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int(), Arb.int()) { a, b, c -> + checkAll(10, Arb.int(), Arb.int(), Arb.int()) { a, b, c -> val r = Atomic("") val modifyGate1 = CompletableDeferred() val modifyGate2 = CompletableDeferred() @@ -103,7 +103,7 @@ class ParZip3Test { } @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { - checkAll(Arb.string(), Arb.int(1..3)) { msg, cancel -> + checkAll(10, Arb.string(), Arb.int(1..3)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip4Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip4Test.kt index 11b668e7f5..78a074a085 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip4Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip4Test.kt @@ -23,7 +23,7 @@ import kotlin.test.Test class ParZip4Test { @Test fun parZip4RunsInParallel() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d -> + checkAll(10, Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d -> val r = Atomic("") val modifyGate1 = CompletableDeferred() val modifyGate2 = CompletableDeferred() @@ -114,7 +114,7 @@ class ParZip4Test { @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { - checkAll(Arb.string(), Arb.int(1..4)) { msg, cancel -> + checkAll(10, Arb.string(), Arb.int(1..4)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip5Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip5Test.kt index a4ee82da26..f46addff18 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip5Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip5Test.kt @@ -23,7 +23,7 @@ import kotlin.test.Test class ParZip5Test { @Test fun parZip5RunsInParallel() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e -> + checkAll(10, Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e -> val r = Atomic("") val modifyGate1 = CompletableDeferred() val modifyGate2 = CompletableDeferred() @@ -137,7 +137,7 @@ class ParZip5Test { @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { - checkAll(Arb.string(), Arb.int(1..5)) { msg, cancel -> + checkAll(10, Arb.string(), Arb.int(1..5)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip6Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip6Test.kt index 8fef5baf9f..ba0c3dfd31 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip6Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip6Test.kt @@ -23,7 +23,7 @@ import kotlin.test.Test class ParZip6Test { @Test fun parZip6RunsInParallel() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f -> + checkAll(10, Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f -> val r = Atomic("") val modifyGate1 = CompletableDeferred() val modifyGate2 = CompletableDeferred() @@ -144,7 +144,7 @@ class ParZip6Test { @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { - checkAll(Arb.string(), Arb.int(1..6)) { msg, cancel -> + checkAll(10, Arb.string(), Arb.int(1..6)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip7Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip7Test.kt index cf7b672da4..19615605dc 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip7Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip7Test.kt @@ -23,7 +23,7 @@ import kotlin.test.Test class ParZip7Test { @Test fun parZip7RunsInParallel() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f, g -> + checkAll(10, Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f, g -> val r = Atomic("") val modifyGate1 = CompletableDeferred() val modifyGate2 = CompletableDeferred() @@ -158,7 +158,7 @@ class ParZip7Test { @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { - checkAll(Arb.string(), Arb.int(1..7)) { msg, cancel -> + checkAll(10, Arb.string(), Arb.int(1..7)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip8Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip8Test.kt index cfae45a045..036d75a5e3 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip8Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip8Test.kt @@ -23,7 +23,7 @@ import kotlin.test.Test class ParZip8Test { @Test fun parZip8RunsInParallel() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f, g, h -> + checkAll(10, Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f, g, h -> val r = Atomic("") val modifyGate1 = CompletableDeferred() val modifyGate2 = CompletableDeferred() @@ -170,7 +170,7 @@ class ParZip8Test { @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { - checkAll(Arb.string(), Arb.int(1..8)) { msg, cancel -> + checkAll(10, Arb.string(), Arb.int(1..8)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip9Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip9Test.kt index 7e22dd8359..6eb3077d8a 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip9Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip9Test.kt @@ -23,7 +23,7 @@ class ParZip9Test { @Test fun parZip9RunsInParallel() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f, g, h, i -> + checkAll(10, Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f, g, h, i -> val r = Atomic("") val modifyGate1 = CompletableDeferred() val modifyGate2 = CompletableDeferred() @@ -183,7 +183,7 @@ class ParZip9Test { @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { - checkAll(Arb.string(), Arb.int(1..9)) { msg, cancel -> + checkAll(10, Arb.string(), Arb.int(1..9)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/RaceNTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/RaceNTest.kt index 8fc5a0cddd..3c3260ca61 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/RaceNTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/RaceNTest.kt @@ -25,19 +25,19 @@ fun Either.rethrow(): A = class RaceNTest { @Test fun race2JoinFirst() = runTestUsingDefaultDispatcher { - checkAll(Arb.int()) { i -> + checkAll(10, Arb.int()) { i -> raceN({ i }, { awaitCancellation() }) shouldBe Either.Left(i) } } @Test fun race2JoinSecond() = runTestUsingDefaultDispatcher { - checkAll(Arb.int()) { i -> + checkAll(10, Arb.int()) { i -> raceN({ awaitCancellation() }, { i }) shouldBe Either.Right(i) } } @Test fun race2CancelsAll() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int()) { a, b -> + checkAll(10, Arb.int(), Arb.int()) { a, b -> val s = Channel() val pa = CompletableDeferred>() val pb = CompletableDeferred>() @@ -89,26 +89,26 @@ class RaceNTest { } @Test fun race3JoinFirst() = runTestUsingDefaultDispatcher { - checkAll(Arb.int()) { i -> + checkAll(10, Arb.int()) { i -> raceN({ i }, { awaitCancellation() }, { awaitCancellation() }) shouldBe Race3.First(i) } } @Test fun race3JoinSecond() = runTestUsingDefaultDispatcher { - checkAll(Arb.int()) { i -> + checkAll(10, Arb.int()) { i -> raceN({ awaitCancellation() }, { i }, { awaitCancellation() }) shouldBe Race3.Second(i) } } @Test fun race3JoinThird() = runTestUsingDefaultDispatcher { - checkAll(Arb.int()) { i -> + checkAll(10, Arb.int()) { i -> raceN({ awaitCancellation() }, { awaitCancellation() }, { i }) shouldBe Race3.Third(i) } } @Test fun race3CancelsAll() = runTestUsingDefaultDispatcher { retry(10, 1.seconds) { - checkAll(Arb.int(), Arb.int(), Arb.int()) { a, b, c -> + checkAll(10, Arb.int(), Arb.int(), Arb.int()) { a, b, c -> val s = Channel() val pa = CompletableDeferred>() val pb = CompletableDeferred>() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt index 41de38cd14..1ee7631206 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt @@ -38,7 +38,7 @@ class ResourceTest { @Test fun acquireSuccessIdentity() = runTest { - checkAll(Arb.int()) { n -> + checkAll(10, Arb.int()) { n -> resourceScope { install({ n }) { _, _ -> } shouldBe n } @@ -47,7 +47,7 @@ class ResourceTest { @Test fun respectFIFOOrderInstalledFunction() = runTest { - checkAll(Arb.positiveInt(), Arb.negativeInt()) { a, b -> + checkAll(10, Arb.positiveInt(), Arb.negativeInt()) { a, b -> val order = mutableListOf() suspend fun ResourceScope.scoped(n: Int): Int = @@ -65,7 +65,7 @@ class ResourceTest { @Test fun resourceReleasedWithComplete() = runTest { - checkAll(Arb.int()) { n -> + checkAll(10, Arb.int()) { n -> val p = CompletableDeferred() resourceScope { install({ n }) { _, ex -> require(p.complete(ex)) } @@ -76,7 +76,7 @@ class ResourceTest { @Test fun errorFinishesWithError() = runTest { - checkAll(Arb.throwable()) { e -> + checkAll(10, Arb.throwable()) { e -> val p = CompletableDeferred() suspend fun ResourceScope.failingScope(): Nothing = install({ throw e }, { _, ex -> require(p.complete(ex)) }) @@ -89,7 +89,7 @@ class ResourceTest { @Test fun neverCancelled() = runTest { - checkAll(Arb.int()) { n -> + checkAll(10, Arb.int()) { n -> val p = CompletableDeferred() val start = CompletableDeferred() suspend fun ResourceScope.n(): Int = install({ n }, { _, ex -> require(p.complete(ex)) }) @@ -233,7 +233,7 @@ class ResourceTest { // Test multiple release triggers on acquire fail. @Test fun parZipFinalizersLeftOrRightCancellation() = runTestUsingDefaultDispatcher { - checkAll(Arb.boolean()) { isLeft -> + checkAll(10, Arb.boolean()) { isLeft -> val cancel = CancellationException(null, null) val (promises, resource) = generate() val latch = CompletableDeferred() @@ -268,7 +268,7 @@ class ResourceTest { @Test fun parZipRightCancellationExceptionOnAcquire() = runTestUsingDefaultDispatcher { - checkAll(Arb.int()) { i -> + checkAll(10, Arb.int()) { i -> val cancel = CancellationException(null, null) val released = CompletableDeferred>() val started = CompletableDeferred() @@ -297,7 +297,7 @@ class ResourceTest { @Test fun parZipLeftCancellationExceptionOnAcquire() = runTestUsingDefaultDispatcher { - checkAll(Arb.int()) { i -> + checkAll(10, Arb.int()) { i -> val cancel = CancellationException(null, null) val released = CompletableDeferred>() val started = CompletableDeferred() @@ -327,7 +327,7 @@ class ResourceTest { @Test fun parZipRightErrorOnAcquire() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.throwable()) { i, throwable -> + checkAll(10, Arb.int(), Arb.throwable()) { i, throwable -> val released = CompletableDeferred>() val started = CompletableDeferred() shouldThrow { @@ -355,7 +355,7 @@ class ResourceTest { @Test fun parZipLeftErrorOnAcquire() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.throwable()) { i, throwable -> + checkAll(10, Arb.int(), Arb.throwable()) { i, throwable -> val released = CompletableDeferred>() val started = CompletableDeferred() shouldThrow { @@ -382,7 +382,7 @@ class ResourceTest { @Test fun parZipRightCancellationExceptionOnRelease() = runTestUsingDefaultDispatcher { - checkAll(Arb.int()) { i -> + checkAll(10, Arb.int()) { i -> val cancel = CancellationException(null, null) val released = CompletableDeferred>() @@ -404,7 +404,7 @@ class ResourceTest { @Test fun parZipLeftCancellationExceptionOnRelease() = runTestUsingDefaultDispatcher { - checkAll(Arb.int()) { i -> + checkAll(10, Arb.int()) { i -> val cancel = CancellationException(null, null) val released = CompletableDeferred>() @@ -426,7 +426,7 @@ class ResourceTest { @Test fun parZipRightErrorOnRelease() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.throwable()) { i, throwable -> + checkAll(10, Arb.int(), Arb.throwable()) { i, throwable -> val released = CompletableDeferred>() shouldThrow { @@ -447,7 +447,7 @@ class ResourceTest { @Test fun parZipLeftErrorOnRelease() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.throwable()) { i, throwable -> + checkAll(10, Arb.int(), Arb.throwable()) { i, throwable -> val released = CompletableDeferred>() shouldThrow { @@ -468,7 +468,7 @@ class ResourceTest { @Test fun parZipErrorInUse() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int(), Arb.throwable()) { a, b, throwable -> + checkAll(10, Arb.int(), Arb.int(), Arb.throwable()) { a, b, throwable -> val releasedA = CompletableDeferred>() val releasedB = CompletableDeferred>() @@ -495,7 +495,7 @@ class ResourceTest { @Test fun parZipCancellationInUse() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(), Arb.int()) { a, b -> + checkAll(10, Arb.int(), Arb.int()) { a, b -> val releasedA = CompletableDeferred>() val releasedB = CompletableDeferred>() @@ -522,7 +522,7 @@ class ResourceTest { @Test fun resourceAsFlow() = runTest { - checkAll(Arb.int()) { n -> + checkAll(10, Arb.int()) { n -> val released = CompletableDeferred() val r = resource({ n }, { _, ex -> require(released.complete(ex)) }) @@ -534,7 +534,7 @@ class ResourceTest { @Test fun resourceAsFlowFail() = runTest { - checkAll(Arb.int(), Arb.throwable()) { n, throwable -> + checkAll(10, Arb.int(), Arb.throwable()) { n, throwable -> val released = CompletableDeferred() val r = resource({ n }, { _, ex -> require(released.complete(ex)) }) @@ -548,7 +548,7 @@ class ResourceTest { @Test fun resourceAsFlowCancel() = runTest { - checkAll(Arb.int()) { n -> + checkAll(10, Arb.int()) { n -> val released = CompletableDeferred() val r = resource({ n }, { _, ex -> require(released.complete(ex)) }) @@ -563,7 +563,7 @@ class ResourceTest { @OptIn(DelicateCoroutinesApi::class) @Test fun allocatedWorks() = runTest { - checkAll(Arb.int()) { seed -> + checkAll(10, Arb.int()) { seed -> val released = CompletableDeferred() val (allocate, release) = resource({ seed }) { _, exitCase -> released.complete(exitCase) } .allocated() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt index 7e1421a311..1de2834991 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt @@ -5,29 +5,31 @@ import io.kotest.matchers.string.shouldContain import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.checkAll +import kotlinx.coroutines.Dispatchers import kotlin.test.Test import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.toList import kotlinx.coroutines.flow.toSet import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.runBlocking @OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) class FlowJvmTest { - @Test fun parMapSingleThreadIdentity() = runTestUsingDefaultDispatcher { + @Test fun parMapSingleThreadIdentity(): Unit = runBlocking(Dispatchers.Default) { resourceScope { val ctx = singleThreadContext("single") - checkAll(Arb.flow(Arb.int())) { flow -> + checkAll(10, Arb.flow(Arb.int())) { flow -> flow.parMap { it }.flowOn(ctx) .toList() shouldBe flow.toList() } } } - @Test fun parMapflowOn() = runTestUsingDefaultDispatcher { + @Test fun parMapflowOn(): Unit = runBlocking(Dispatchers.Default) { resourceScope { val ctx = singleThreadContext("single") - checkAll(Arb.flow(Arb.int())) { flow -> + checkAll(10, Arb.flow(Arb.int())) { flow -> flow.parMap { Thread.currentThread().name }.flowOn(ctx) .toList().forEach { it shouldContain "single" @@ -36,20 +38,20 @@ class FlowJvmTest { } } - @Test fun parMapUnorderedSingleThreadIdentity() = runTestUsingDefaultDispatcher { + @Test fun parMapUnorderedSingleThreadIdentity(): Unit = runBlocking(Dispatchers.Default) { resourceScope { val ctx = singleThreadContext("single") - checkAll(Arb.flow(Arb.int())) { flow -> + checkAll(10, Arb.flow(Arb.int())) { flow -> flow.parMapUnordered { it }.flowOn(ctx) .toSet() shouldBe flow.toSet() } } } - @Test fun parMapUnorderedFlowOn() = runTestUsingDefaultDispatcher { + @Test fun parMapUnorderedFlowOn(): Unit = runBlocking(Dispatchers.Default) { resourceScope { val ctx = singleThreadContext("single") - checkAll(Arb.flow(Arb.int())) { flow -> + checkAll(10, Arb.flow(Arb.int())) { flow -> flow.parMap { Thread.currentThread().name }.flowOn(ctx) .toList().forEach { it shouldContain "single" diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt index 71f1617df6..ac8ac91dd3 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt @@ -5,11 +5,13 @@ import io.kotest.matchers.string.shouldStartWith import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.checkAll +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.runBlocking import kotlin.test.Test class ParMapJvmTest { - @Test fun parMapRunsOnProvidedContext() = runTestUsingDefaultDispatcher { // 100 is same default length as Arb.list - checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> + @Test fun parMapRunsOnProvidedContext(): Unit = runBlocking(Dispatchers.Default) { // 100 is same default length as Arb.list + checkAll(10, Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMap(single()) { Thread.currentThread().name } } @@ -17,8 +19,8 @@ class ParMapJvmTest { } } - @Test fun parMapConcurrency3RunsOnProvidedContext() = runTestUsingDefaultDispatcher { - checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> + @Test fun parMapConcurrency3RunsOnProvidedContext(): Unit = runBlocking(Dispatchers.Default) { + checkAll(10, Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMap(single(), concurrency = 3) { Thread.currentThread().name @@ -28,8 +30,8 @@ class ParMapJvmTest { } } - @Test fun parMapOrAccumulateCombineEmptyErrorRunsOnProvidedContext() = runTestUsingDefaultDispatcher { // 100 is same default length as Arb.list - checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> + @Test fun parMapOrAccumulateCombineEmptyErrorRunsOnProvidedContext(): Unit = runBlocking(Dispatchers.Default) { // 100 is same default length as Arb.list + checkAll(10, Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMapOrAccumulate(single(), combine = emptyError) { Thread.currentThread().name } } @@ -40,8 +42,8 @@ class ParMapJvmTest { } } - @Test fun parMapOrAccumulateCombineEmptyErrorConcurrency3RunsOnProvidedContext() = runTestUsingDefaultDispatcher { // 100 is same default length as Arb.list - checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> + @Test fun parMapOrAccumulateCombineEmptyErrorConcurrency3RunsOnProvidedContext(): Unit = runBlocking(Dispatchers.Default) { // 100 is same default length as Arb.list + checkAll(10, Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMapOrAccumulate( single(), @@ -56,8 +58,8 @@ class ParMapJvmTest { } } - @Test fun parMapOrAccumulateRunsOnProvidedContext() = runTestUsingDefaultDispatcher { // 100 is same default length as Arb.list - checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> + @Test fun parMapOrAccumulateRunsOnProvidedContext(): Unit = runBlocking(Dispatchers.Default) { // 100 is same default length as Arb.list + checkAll(10, Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMapOrAccumulate(single()) { Thread.currentThread().name @@ -70,8 +72,8 @@ class ParMapJvmTest { } } - @Test fun parMapOrAccumulateConcurrency3RunsOnProvidedContext() = runTestUsingDefaultDispatcher { // 100 is same default length as Arb.list - checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> + @Test fun parMapOrAccumulateConcurrency3RunsOnProvidedContext(): Unit = runBlocking(Dispatchers.Default) { // 100 is same default length as Arb.list + checkAll(10, Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMapOrAccumulate(single(), concurrency = 3) { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt index 09b631ff25..ff84fa6406 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt @@ -5,75 +5,83 @@ import io.kotest.assertions.assertSoftly import io.kotest.matchers.should import io.kotest.matchers.string.shouldStartWith import io.kotest.mpp.NamedThreadFactory -import io.kotest.property.Arb -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.string -import io.kotest.property.checkAll import java.util.concurrent.Executors -import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.withContext import kotlin.coroutines.CoroutineContext import kotlin.test.Test -import kotlin.time.Duration.Companion.seconds +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withContext class ParZip2JvmTest { - @Test fun parZip2ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { - val zipCtxName = "parZip2" - resourceScope { - val zipCtx = executor { Executors.newFixedThreadPool(2, NamedThreadFactory(zipCtxName)) } - withContext(single()) { - Thread.currentThread().name shouldStartWith "single" + @Test + fun parZip2ReturnsToOriginalContext(): Unit = + runBlocking(context = Dispatchers.Default) { + val zipCtxName = "parZip2" + resourceScope { + val zipCtx = executor { Executors.newFixedThreadPool(2, NamedThreadFactory(zipCtxName)) } + withContext(single()) { + Thread.currentThread().name shouldStartWith "single" - val (s1, s2) = parZip( - zipCtx, - { Thread.currentThread().name }, - { Thread.currentThread().name }) { a, b -> Pair(a, b) } + val (s1, s2) = + parZip(zipCtx, { Thread.currentThread().name }, { Thread.currentThread().name }) { + a, + b -> + Pair(a, b) + } - s1 shouldStartWith zipCtxName - s2 shouldStartWith zipCtxName - Thread.currentThread().name shouldStartWith "single" + s1 shouldStartWith zipCtxName + s2 shouldStartWith zipCtxName + Thread.currentThread().name shouldStartWith "single" + } + } } - } - } - @Test fun parZip2ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { - val zipCtxName = "parZip2" - resourceScope { - val zipCtx = executor { Executors.newFixedThreadPool(2, NamedThreadFactory(zipCtxName)) } - checkAll(Arb.int(1..2), Arb.throwable()) { choose, e -> - withContext(single()) { - Thread.currentThread().name shouldStartWith "single" - Either.catch { - when (choose) { - 1 -> parZip(zipCtx, { throw e }, { awaitCancellation() }) { _, _ -> Unit } - else -> parZip(zipCtx, { awaitCancellation() }, { throw e }) { _, _ -> Unit } - } - } should leftException(e) + @Test + fun parZip2ReturnsToOriginalContextOnFailureRight(): Unit = + parZip2ReturnsToOriginalContextOnFailure(true) - Thread.currentThread().name shouldStartWith "single" + @Test + fun parZip2ReturnsToOriginalContextOnFailureLeft(): Unit = + parZip2ReturnsToOriginalContextOnFailure(false) + + private fun parZip2ReturnsToOriginalContextOnFailure(choose: Boolean): Unit = + runBlocking(context = Dispatchers.Default) { + val zipCtxName = "parZip2" + resourceScope { + val zipCtx = executor { Executors.newFixedThreadPool(2, NamedThreadFactory(zipCtxName)) } + val e = RuntimeException("Boom") + withContext(single()) { + Thread.currentThread().name shouldStartWith "single" + + Either.catch { + if (choose) parZip(zipCtx, { throw e }, { awaitCancellation() }) { _, _ -> Unit } + else parZip(zipCtx, { awaitCancellation() }, { throw e }) { _, _ -> Unit } + } should leftException(e) + + Thread.currentThread().name shouldStartWith "single" + } } } - } - } - @Test fun parZip2FinishesOnSingleThread() = runTestUsingDefaultDispatcher { - checkAll(Arb.string()) { - val res = resourceScope { - val ctx = singleThreadContext("single") - parZip(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }) { a, b -> listOf(a, b) } - } - assertSoftly { - res.forEach { it shouldStartWith "single" } + @Test + fun parZip2FinishesOnSingleThread(): Unit = + runBlocking(context = Dispatchers.Default) { + val res = resourceScope { + val ctx = singleThreadContext("single") + parZip(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }) { a, b -> + listOf(a, b) + } + } + assertSoftly { res.forEach { it shouldStartWith "single" } } } - } - } } suspend fun parallelCtx( - nThreads: Int, - mapCtxName: String, - use: suspend (CoroutineContext, CoroutineContext) -> Unit, + nThreads: Int, + mapCtxName: String, + use: suspend (CoroutineContext, CoroutineContext) -> Unit, ): Unit = resourceScope { use(singleThreadContext("single"), fixedThreadPoolContext(nThreads, mapCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt index 4a2bc4ae88..49ca6111e0 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt @@ -9,14 +9,16 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.Dispatchers import java.util.concurrent.Executors import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import kotlin.test.Test import kotlin.time.Duration.Companion.seconds class ParZip3JvmTest { - @Test fun parZip3ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { + @Test fun parZip3ReturnsToOriginalContext(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip3" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(3, NamedThreadFactory(zipCtxName)) } @@ -36,12 +38,12 @@ class ParZip3JvmTest { } } - @Test fun parZip3ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip3ReturnsToOriginalContextOnFailure(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip3" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(3, NamedThreadFactory(zipCtxName)) } - checkAll(Arb.int(1..3), Arb.throwable()) { choose, e -> + checkAll(10, Arb.int(1..3), Arb.throwable()) { choose, e -> withContext(single()) { Thread.currentThread().name shouldStartWith "single" @@ -76,8 +78,8 @@ class ParZip3JvmTest { } } - @Test fun parZip3FinishesOnSingleThread() = runTestUsingDefaultDispatcher { - checkAll(Arb.string()) { + @Test fun parZip3FinishesOnSingleThread(): Unit = runBlocking(Dispatchers.Default) { + checkAll(10, Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") parZip( diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt index 763b8c14f2..f80bd55470 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt @@ -10,14 +10,16 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.Dispatchers import java.util.concurrent.Executors import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import kotlin.test.Test import kotlin.time.Duration.Companion.seconds class ParZip4JvmTest { - @Test fun parZip4ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { + @Test fun parZip4ReturnsToOriginalContext(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip4" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(4, NamedThreadFactory(zipCtxName)) } @@ -42,12 +44,12 @@ class ParZip4JvmTest { } } - @Test fun parZip4ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip4ReturnsToOriginalContextOnFailure(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip4" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(4, NamedThreadFactory(zipCtxName)) } - checkAll(Arb.int(1..4), Arb.throwable()) { choose, e -> + checkAll(10, Arb.int(1..4), Arb.throwable()) { choose, e -> withContext(single()) { Thread.currentThread().name shouldStartWith "single" @@ -93,8 +95,8 @@ class ParZip4JvmTest { } } - @Test fun parZip4FinishesOnSingleThread() = runTestUsingDefaultDispatcher { - checkAll(Arb.string()) { + @Test fun parZip4FinishesOnSingleThread(): Unit = runBlocking(Dispatchers.Default) { + checkAll(10, Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") parZip( diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt index ad6869b306..3562d9b300 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt @@ -10,10 +10,8 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.* import java.util.concurrent.Executors -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.withContext import kotlin.test.Test import kotlin.time.Duration.Companion.seconds @@ -21,7 +19,7 @@ class ParZip5JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - @Test fun parZip5ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { + @Test fun parZip5ReturnsToOriginalContext(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip5" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(5, NamedThreadFactory(zipCtxName)) } @@ -43,12 +41,12 @@ class ParZip5JvmTest { } } - @Test fun parZip5ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip5ReturnsToOriginalContextOnFailure(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip5" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(5, NamedThreadFactory(zipCtxName)) } - checkAll(Arb.int(1..5), Arb.throwable()) { choose, e -> + checkAll(10, Arb.int(1..5), Arb.throwable()) { choose, e -> withContext(single()) { threadName() shouldStartWith "single" @@ -107,8 +105,8 @@ class ParZip5JvmTest { } } - @Test fun parZip5FinishesOnSingleThread() = runTestUsingDefaultDispatcher { - checkAll(Arb.string()) { + @Test fun parZip5FinishesOnSingleThread(): Unit = runBlocking(Dispatchers.Default) { + checkAll(10, Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") parZip(ctx, threadName, threadName, threadName, threadName, threadName) { a, b, c, d, e -> diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt index 1e37b0e876..6e327e9c2e 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt @@ -10,10 +10,8 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.* import java.util.concurrent.Executors -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.withContext import kotlin.test.Test import kotlin.time.Duration.Companion.seconds @@ -21,7 +19,7 @@ class ParZip6JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - @Test fun parZip6ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { + @Test fun parZip6ReturnsToOriginalContext(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip6" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(6, NamedThreadFactory(zipCtxName)) } @@ -46,12 +44,12 @@ class ParZip6JvmTest { } } - @Test fun parZip6ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip6ReturnsToOriginalContextOnFailure(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip6" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(6, NamedThreadFactory(zipCtxName)) } - checkAll(Arb.int(1..6), Arb.throwable()) { choose, e -> + checkAll(10, Arb.int(1..6), Arb.throwable()) { choose, e -> withContext(single()) { threadName() shouldStartWith "single" @@ -124,8 +122,8 @@ class ParZip6JvmTest { } } - @Test fun parZip6FinishesOnSingleThread() = runTestUsingDefaultDispatcher { - checkAll(Arb.string()) { + @Test fun parZip6FinishesOnSingleThread(): Unit = runBlocking(Dispatchers.Default) { + checkAll(10, Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") parZip(ctx, threadName, threadName, threadName, threadName, threadName, threadName) { a, b, c, d, e, f -> diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt index fe8d2fc5e8..50a2a6b117 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt @@ -10,10 +10,8 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.* import java.util.concurrent.Executors -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.withContext import kotlin.test.Test import kotlin.time.Duration.Companion.seconds @@ -21,7 +19,7 @@ class ParZip7JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - @Test fun parZip7ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { + @Test fun parZip7ReturnsToOriginalContext(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip7" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(7, NamedThreadFactory(zipCtxName)) } @@ -47,12 +45,12 @@ class ParZip7JvmTest { } } - @Test fun parZip7ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip7ReturnsToOriginalContextOnFailure(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip7" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(7, NamedThreadFactory(zipCtxName)) } - checkAll(Arb.int(1..7), Arb.throwable()) { choose, e -> + checkAll(10, Arb.int(1..7), Arb.throwable()) { choose, e -> withContext(single()) { threadName() shouldStartWith "single" @@ -142,8 +140,8 @@ class ParZip7JvmTest { } } - @Test fun parZip7FinishesOnSingleThread() = runTestUsingDefaultDispatcher { - checkAll(Arb.string()) { + @Test fun parZip7FinishesOnSingleThread(): Unit = runBlocking(Dispatchers.Default) { + checkAll(10, Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") parZip( diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt index 25d90771a3..1d53c7c26c 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt @@ -10,10 +10,8 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.* import java.util.concurrent.Executors -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.withContext import kotlin.test.Test import kotlin.time.Duration.Companion.seconds @@ -21,7 +19,7 @@ class ParZip8JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - @Test fun parZip8ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { + @Test fun parZip8ReturnsToOriginalContext(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip8" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(8, NamedThreadFactory(zipCtxName)) } @@ -48,12 +46,12 @@ class ParZip8JvmTest { } - @Test fun parZip8ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip8ReturnsToOriginalContextOnFailure(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip8" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(8, NamedThreadFactory(zipCtxName)) } - checkAll(Arb.int(1..8), Arb.throwable()) { choose, e -> + checkAll(10, Arb.int(1..8), Arb.throwable()) { choose, e -> withContext(single()) { threadName() shouldStartWith "single" @@ -160,8 +158,8 @@ class ParZip8JvmTest { } } - @Test fun parZip8FinishesOnSingleThread() = runTestUsingDefaultDispatcher { - checkAll(Arb.string()) { + @Test fun parZip8FinishesOnSingleThread(): Unit = runBlocking(Dispatchers.Default) { + checkAll(10, Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") parZip( diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt index 89d18c47c8..ae7f86a2db 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt @@ -10,9 +10,7 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import io.kotest.property.checkAll -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.withContext +import kotlinx.coroutines.* import kotlin.test.Test import java.util.concurrent.Executors import kotlin.time.Duration.Companion.seconds @@ -21,7 +19,7 @@ class ParZip9JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - @Test fun parZip9ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { + @Test fun parZip9ReturnsToOriginalContext(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip9" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(9, NamedThreadFactory(zipCtxName)) } @@ -58,12 +56,12 @@ class ParZip9JvmTest { } - @Test fun parZip9ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip9ReturnsToOriginalContextOnFailure(): Unit = runBlocking(Dispatchers.Default) { val zipCtxName = "parZip9" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(9, NamedThreadFactory(zipCtxName)) } - checkAll(Arb.int(1..9), Arb.throwable()) { choose, e -> + checkAll(10, Arb.int(1..9), Arb.throwable()) { choose, e -> withContext(single()) { threadName() shouldStartWith "single" @@ -193,8 +191,8 @@ class ParZip9JvmTest { } } - @Test fun parZip9FinishesOnSingleThread() = runTestUsingDefaultDispatcher { - checkAll(Arb.string()) { + @Test fun parZip9FinishesOnSingleThread(): Unit = runBlocking(Dispatchers.Default) { + checkAll(10, Arb.string()) { val res = resourceScope { parZip( single(), diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt index 83f56602c8..941f0b7f4c 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt @@ -4,120 +4,156 @@ import arrow.core.Either import arrow.core.identity import io.kotest.matchers.should import io.kotest.matchers.string.shouldStartWith -import io.kotest.property.Arb -import io.kotest.property.arbitrary.int -import io.kotest.property.checkAll +import kotlin.test.Test +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext -import kotlin.test.Test -import kotlin.time.Duration.Companion.seconds class RaceNJvmTest { - @Test fun race2ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { - val racerName = "race2" - checkAll(Arb.int(1..2)) { choose -> + private fun race2ReturnsToOriginalContext(choose: Boolean): Unit = + runBlocking(Dispatchers.Default) { + val racerName = "race2" resourceScope { val pool = fixedThreadPoolContext(2, racerName) withContext(singleThreadContext("single")) { Thread.currentThread().name shouldStartWith "single" - - val racedOn = when (choose) { - 1 -> raceN(pool, { Thread.currentThread().name }, { awaitCancellation() }).swap().getOrNull() - else -> raceN(pool, { awaitCancellation() }, { Thread.currentThread().name }).getOrNull() - } - + + val racedOn = + if (choose) + raceN( + pool, { Thread.currentThread().name }, { awaitCancellation() }) + .swap() + .getOrNull() + else + raceN( + pool, { awaitCancellation() }, { Thread.currentThread().name }) + .getOrNull() + racedOn shouldStartWith racerName Thread.currentThread().name shouldStartWith "single" } } } - } - @Test fun race2ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { - val racerName = "race2" - - checkAll(Arb.int(1..2), Arb.throwable()) { choose, e -> + @Test fun race2ReturnsToOriginalContextRight() = race2ReturnsToOriginalContext(true) + + @Test fun race2ReturnsToOriginalContextLeft() = race2ReturnsToOriginalContext(false) + + private fun race2ReturnsToOriginalContextOnFailure(right: Boolean): Unit = + runBlocking(Dispatchers.Default) { + val racerName = "race2" + resourceScope { val pool = fixedThreadPoolContext(2, racerName) + val e = RuntimeException("Boom") withContext(singleThreadContext("single")) { Thread.currentThread().name shouldStartWith "single" - Either.catch { - when (choose) { - 1 -> raceN(pool, { throw e }, { awaitCancellation() }).swap().getOrNull() - else -> raceN(pool, { awaitCancellation() }, { throw e }).getOrNull() - } + if (right) raceN(pool, { throw e }, { awaitCancellation() }).swap().getOrNull() + else raceN(pool, { awaitCancellation() }, { throw e }).getOrNull() } should leftException(e) - + Thread.currentThread().name shouldStartWith "single" } } } - } - - @Test fun firstRacerOutOf2AlwaysWinsOnASingleThread() = runTestUsingDefaultDispatcher { - resourceScope { - val ctx = singleThreadContext("single") - raceN(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }) - }.swap().getOrNull() shouldStartWith "single" - } - - @Test fun race3ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { - val racerName = "race3" - - checkAll(Arb.int(1..3)) { choose -> + + @Test + fun race2ReturnsToOriginalContextOnFailureLeft(): Unit = + race2ReturnsToOriginalContextOnFailure(false) + + @Test + fun race2ReturnsToOriginalContextOnFailureRight(): Unit = + race2ReturnsToOriginalContextOnFailure(true) + + @Test + fun firstRacerOutOf2AlwaysWinsOnASingleThread(): Unit = + runBlocking(Dispatchers.Default) { + resourceScope { + val ctx = singleThreadContext("single") + raceN(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }) + } + .swap() + .getOrNull() shouldStartWith "single" + } + + @Test fun race3ReturnsToOriginalContextRight(): Unit = race3ReturnsToOriginalContext(true) + + @Test fun race3ReturnsToOriginalContextMiddle(): Unit = race3ReturnsToOriginalContext(false) + + @Test fun race3ReturnsToOriginalContextLast(): Unit = race3ReturnsToOriginalContext(null) + + private fun race3ReturnsToOriginalContext(choose: Boolean?): Unit = + runBlocking(Dispatchers.Default) { + val racerName = "race3" parallelCtx(3, racerName) { single, raceCtx -> withContext(single) { Thread.currentThread().name shouldStartWith "single" - - val racedOn = when (choose) { - 1 -> - raceN(raceCtx, { Thread.currentThread().name }, { awaitCancellation() }, { awaitCancellation() }) - .fold(::identity, { null }, { null }) - - 2 -> - raceN(raceCtx, { awaitCancellation() }, { Thread.currentThread().name }, { awaitCancellation() }) - .fold({ null }, ::identity, { null }) - - else -> - raceN(raceCtx, { awaitCancellation() }, { awaitCancellation() }, { Thread.currentThread().name }) - .fold({ null }, { null }, ::identity) - } - + + val racedOn = + when (choose) { + true -> + raceN( + raceCtx, + { Thread.currentThread().name }, + { awaitCancellation() }, + { awaitCancellation() }) + .fold(::identity, { null }, { null }) + + false -> + raceN( + raceCtx, + { awaitCancellation() }, + { Thread.currentThread().name }, + { awaitCancellation() }) + .fold({ null }, ::identity, { null }) + + null -> + raceN( + raceCtx, + { awaitCancellation() }, + { awaitCancellation() }, + { Thread.currentThread().name }) + .fold({ null }, { null }, ::identity) + } + racedOn shouldStartWith racerName Thread.currentThread().name shouldStartWith "single" } } } - } - - @Test fun race3ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { - val racerName = "race3" - - checkAll(Arb.int(1..3), Arb.throwable()) { choose, e -> + + @Test fun race3ReturnsToOriginalContextOnFailureRight(): Unit = race3ReturnsToOriginalContextOnFailure(true) + @Test fun race3ReturnsToOriginalContextOnFailureMiddle(): Unit = race3ReturnsToOriginalContextOnFailure(false) + @Test fun race3ReturnsToOriginalContextOnFailureLast(): Unit = race3ReturnsToOriginalContextOnFailure(null) + + private fun race3ReturnsToOriginalContextOnFailure(choose: Boolean?): Unit = + runBlocking(Dispatchers.Default) { + val racerName = "race3" + val e = RuntimeException("Boom") parallelCtx(3, racerName) { single, raceCtx -> withContext(single) { Thread.currentThread().name shouldStartWith "single" - + Either.catch { when (choose) { - 1 -> - raceN(raceCtx, { throw e }, { awaitCancellation() }, { awaitCancellation() }) - .fold({ x: String? -> x }, { null }, { null }) - - 2 -> - raceN(raceCtx, { awaitCancellation() }, { throw e }, { awaitCancellation() }) - .fold({ null }, { x: String? -> x }, { null }) - - else -> - raceN(raceCtx, { awaitCancellation() }, { awaitCancellation() }, { throw e }) - .fold({ null }, { null }, { x: String? -> x }) + true -> + raceN(raceCtx, { throw e }, { awaitCancellation() }, { awaitCancellation() }) + .fold({ x: String? -> x }, { null }, { null }) + + false -> + raceN(raceCtx, { awaitCancellation() }, { throw e }, { awaitCancellation() }) + .fold({ null }, { x: String? -> x }, { null }) + + null -> + raceN(raceCtx, { awaitCancellation() }, { awaitCancellation() }, { throw e }) + .fold({ null }, { null }, { x: String? -> x }) } } should leftException(e) - + Thread.currentThread().name shouldStartWith "single" } } } - } - } +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ResourceTestJvm.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ResourceTestJvm.kt index 20f21fd44c..f71f670ba0 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ResourceTestJvm.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ResourceTestJvm.kt @@ -35,7 +35,7 @@ class ResourceTestJvm { } @Test fun autoCloseableClosesOnError() = runTest { - checkAll(Arb.throwable()) { throwable -> + checkAll(10, Arb.throwable()) { throwable -> val t = AutoCloseableTest() shouldThrow { @@ -60,7 +60,7 @@ class ResourceTestJvm { } @Test fun closeableClosesOnError() = runTest { - checkAll(Arb.throwable()) { throwable -> + checkAll(10, Arb.throwable()) { throwable -> val t = CloseableTest() shouldThrow {