Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ParZip5Test.kt #3269

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import arrow.fx.coroutines.awaitExitCase
import arrow.fx.coroutines.leftException
import arrow.fx.coroutines.parZip
import arrow.fx.coroutines.throwable
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.shouldBeTypeOf
Expand All @@ -22,9 +21,12 @@ import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.async
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.test.runTest
import kotlin.test.Test

class ParZip5Test : StringSpec({
"parZip 5 runs in parallel" {
class ParZip5Test {
@Test
fun parZip5RunsInParallel() = runTest {
checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e ->
val r = Atomic("")
val modifyGate1 = CompletableDeferred<Unit>()
Expand Down Expand Up @@ -63,8 +65,9 @@ class ParZip5Test : StringSpec({
r.get() shouldBe "$e$d$c$b$a"
}
}

"Cancelling parZip 5 cancels all participants" {

@Test
fun CancellingParZip5CancelsAllParticipants() = runTest {
val s = Channel<Unit>()
val pa = CompletableDeferred<ExitCase>()
val pb = CompletableDeferred<ExitCase>()
Expand Down Expand Up @@ -99,8 +102,9 @@ class ParZip5Test : StringSpec({
pd.await().shouldBeTypeOf<ExitCase.Cancelled>()
pe.await().shouldBeTypeOf<ExitCase.Cancelled>()
}

"parZip 5 cancels losers if a failure occurs in one of the tasks" {

@Test
fun parZip5CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest {
checkAll(
Arb.throwable(),
Arb.element(listOf(1, 2, 3, 4, 5)),
Expand Down Expand Up @@ -134,8 +138,9 @@ class ParZip5Test : StringSpec({
r should leftException(e)
}
}

"parZip CancellationException on right can cancel rest" {

@Test
fun parZipCancellationExceptionOnRightCanCancelRest() = runTest {
checkAll(Arb.string(), Arb.int(1..5)) { msg, cancel ->
val s = Channel<Unit>()
val pa = CompletableDeferred<ExitCase>()
Expand Down Expand Up @@ -167,4 +172,3 @@ class ParZip5Test : StringSpec({
}
}
}
)