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

Upgrade to kotlinx-coroutines 1.6.0 #2606

Merged
merged 5 commits into from Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,8 +1,10 @@
package arrow.fx.coroutines

import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.awaitCancellation

// TODO deprecate?
public suspend fun <A> never(): A =
suspendCancellableCoroutine<Nothing> {}
awaitCancellation()

// TODO deprecate?
public suspend fun unit(): Unit = Unit
Expand Up @@ -5,18 +5,18 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.shouldBeTypeOf
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.checkAll
import io.kotest.property.arbitrary.positiveInts
import kotlinx.coroutines.CancellationException
import kotlin.time.ExperimentalTime
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.reduce
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.flow.toSet
import kotlinx.coroutines.launch
import kotlin.time.ExperimentalTime

@ExperimentalTime
class FlowTest : ArrowFxSpec(
Expand Down Expand Up @@ -72,28 +72,22 @@ class FlowTest : ArrowFxSpec(
}

"parMap - triggers cancel signal" {
checkAll(Arb.int(), Arb.int(1..2)) { i, n ->
checkAll {
val latch = CompletableDeferred<Unit>()
val exit = CompletableDeferred<Pair<Int, ExitCase>>()
val exit = CompletableDeferred<ExitCase>()

assertThrowable {
flowOf(1, 2).parMap { index ->
if (index == n) {
guaranteeCase({
latch.complete(Unit)
never<Unit>()
}, { ex -> exit.complete(Pair(i, ex)) })
} else {
latch.await()
throw CancellationException(null, null)
}
val job = launch {
flowOf(1).parMap { index ->
guaranteeCase({
latch.complete(Unit)
awaitCancellation()
}, { ex -> exit.complete(ex) })
}.collect()
fail("Cannot reach here. CancellationException should be thrown.")
}.shouldBeTypeOf<CancellationException>()

val (ii, ex) = exit.await()
ii shouldBe i
ex.shouldBeTypeOf<ExitCase.Cancelled>()
}
latch.await()
job.cancelAndJoin()
job.isCancelled shouldBe true
exit.await().shouldBeTypeOf<ExitCase.Cancelled>()
}
}

Expand All @@ -107,7 +101,7 @@ class FlowTest : ArrowFxSpec(
if (index == n) {
guaranteeCase({
latch.complete(Unit)
never<Unit>()
awaitCancellation()
}, { ex -> exit.complete(Pair(i, ex)) })
} else {
latch.await()
Expand All @@ -133,7 +127,7 @@ class FlowTest : ArrowFxSpec(
flowOf(1, 2).parMap { index ->
guaranteeCase({
if (index == 2) latch.complete(Unit)
never<Unit>()
awaitCancellation()
}, { ex ->
if (index == 1) exitA.complete(Pair(i, ex))
else exitB.complete(Pair(i2, ex))
Expand Down Expand Up @@ -175,28 +169,23 @@ class FlowTest : ArrowFxSpec(
}

"parMapUnordered - triggers cancel signal" {
checkAll(Arb.int(), Arb.int(1..2)) { i, n ->
checkAll {
val latch = CompletableDeferred<Unit>()
val exit = CompletableDeferred<Pair<Int, ExitCase>>()
val exit = CompletableDeferred<ExitCase>()

assertThrowable {
flowOf(1, 2).parMapUnordered { index ->
if (index == n) {
guaranteeCase({
latch.complete(Unit)
never<Unit>()
}, { ex -> exit.complete(Pair(i, ex)) })
} else {
latch.await()
throw CancellationException(null, null)
}
val job = launch {
flowOf(1).parMapUnordered {
guaranteeCase({
latch.complete(Unit)
awaitCancellation()
}, { ex -> exit.complete(ex) })
}.collect()
fail("Cannot reach here. CancellationException should be thrown.")
}.shouldBeTypeOf<CancellationException>()
}
latch.await()
job.cancelAndJoin()

val (ii, ex) = exit.await()
ii shouldBe i
ex.shouldBeTypeOf<ExitCase.Cancelled>()
job.isCancelled shouldBe true
exit.await().shouldBeTypeOf<ExitCase.Cancelled>()
}
}

Expand All @@ -210,7 +199,7 @@ class FlowTest : ArrowFxSpec(
if (index == n) {
guaranteeCase({
latch.complete(Unit)
never<Unit>()
awaitCancellation()
}, { ex -> exit.complete(Pair(i, ex)) })
} else {
latch.await()
Expand All @@ -236,7 +225,7 @@ class FlowTest : ArrowFxSpec(
flowOf(1, 2).parMapUnordered { index ->
guaranteeCase({
if (index == 2) latch.complete(Unit)
never<Unit>()
awaitCancellation()
}, { ex ->
if (index == 1) exitA.complete(Pair(i, ex))
else exitB.complete(Pair(i2, ex))
Expand Down
Expand Up @@ -14,6 +14,7 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.flow.toSet
import kotlinx.coroutines.test.currentTime
import kotlinx.coroutines.test.runBlockingTest
import kotlin.time.ExperimentalTime
import kotlin.time.milliseconds
Expand Down
Expand Up @@ -4,7 +4,6 @@ import arrow.fx.coroutines.ArrowFxSpec
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.pair
import io.kotest.property.arbitrary.map

class TMapTest : ArrowFxSpec(
Expand All @@ -17,7 +16,7 @@ class TMapTest : ArrowFxSpec(
}
}
"insert multiple values" {
checkAll(Arb.list(Arb.pair(Arb.int(), Arb.int())).map { it.distinct() }) { pairs ->
checkAll(Arb.map(Arb.int(), Arb.int())) { pairs ->
val map = TMap.new<Int, Int>()
atomically {
for ((k, v) in pairs) map.insert(k, v)
Expand All @@ -28,7 +27,7 @@ class TMapTest : ArrowFxSpec(
}
}
"insert multiple colliding values" {
checkAll(Arb.list(Arb.pair(Arb.int(), Arb.int()))) { pairs ->
checkAll(Arb.map(Arb.int(), Arb.int())) { pairs ->
val map = TMap.new<Int, Int> { 0 } // hash function that always returns 0
atomically {
for ((k, v) in pairs) map.insert(k, v)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Expand Up @@ -2,7 +2,7 @@
animalSniffer = "1.5.0"
arrowGradleConfig = "0.6.0-alpha.4"
assertj = "3.21.0"
coroutines = "1.5.2"
coroutines = "1.6.0"
classgraph = "4.8.137"
dokka = "1.5.30"
jUnit = "4.12"
Expand Down