From f72ce81d8a37bd3c2c7cdf4256903dbe23e55239 Mon Sep 17 00:00:00 2001 From: i-walker <46971368+i-walker@users.noreply.github.com> Date: Wed, 23 Dec 2020 11:32:22 +0100 Subject: [PATCH 1/3] group module build settings, inline sleep/ timeOutOrNull and replace arrow Duration with kotlin.time.Duration --- arrow-fx-coroutines-stream/build.gradle | 8 -- .../arrow/fx/coroutines/stream/Stream.kt | 7 +- .../arrow/fx/coroutines/stream/BracketTest.kt | 8 +- .../fx/coroutines/stream/CallbackTest.kt | 10 +-- .../fx/coroutines/stream/ConcurrentlyTest.kt | 10 +-- .../fx/coroutines/stream/InterruptionTest.kt | 44 +++++----- .../arrow/fx/coroutines/stream/ParJoinTest.kt | 4 +- .../coroutines/stream/concurrent/QueueTest.kt | 14 +-- arrow-fx-coroutines-test/build.gradle | 8 -- arrow-fx-coroutines/build.gradle | 8 -- .../kotlin/arrow/fx/coroutines/Schedule.kt | 5 +- .../arrow/fx/coroutines/BracketCaseTest.kt | 3 +- .../arrow/fx/coroutines/CancelBoundary.kt | 3 +- .../arrow/fx/coroutines/CancellableF.kt | 3 +- .../arrow/fx/coroutines/CircuitBreakerTest.kt | 5 +- .../arrow/fx/coroutines/ConcurrentVarTest.kt | 13 +-- .../arrow/fx/coroutines/EnvironmentTest.kt | 3 +- arrow-fx-stm/build.gradle | 8 -- .../src/test/kotlin/arrow/fx/stm/STMTest.kt | 14 +-- .../src/test/kotlin/arrow/fx/stm/TVarTest.kt | 10 +-- arrow-fx/src/test/kotlin/arrow/fx/IOTest.kt | 42 +++++---- build.gradle | 88 ++++++++++++------- 22 files changed, 163 insertions(+), 155 deletions(-) diff --git a/arrow-fx-coroutines-stream/build.gradle b/arrow-fx-coroutines-stream/build.gradle index fd5b84db1..d530240cc 100644 --- a/arrow-fx-coroutines-stream/build.gradle +++ b/arrow-fx-coroutines-stream/build.gradle @@ -1,13 +1,5 @@ -plugins { - id "org.jetbrains.kotlin.jvm" - id "org.jlleitschuh.gradle.ktlint" -} - apply plugin: 'kotlinx-atomicfu' -apply from: "$SUB_PROJECT" -apply from: "$DOC_CREATION" - dependencies { api "io.arrow-kt:arrow-core:$VERSION_NAME" implementation project(":arrow-fx-coroutines") diff --git a/arrow-fx-coroutines-stream/src/main/kotlin/arrow/fx/coroutines/stream/Stream.kt b/arrow-fx-coroutines-stream/src/main/kotlin/arrow/fx/coroutines/stream/Stream.kt index 0232b811a..9e21c2390 100644 --- a/arrow-fx-coroutines-stream/src/main/kotlin/arrow/fx/coroutines/stream/Stream.kt +++ b/arrow-fx-coroutines-stream/src/main/kotlin/arrow/fx/coroutines/stream/Stream.kt @@ -9,7 +9,6 @@ import arrow.core.Some import arrow.core.extensions.list.foldable.foldLeft import arrow.core.identity import arrow.fx.coroutines.ComputationPool -import arrow.fx.coroutines.Duration import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.Fiber import arrow.fx.coroutines.ForkAndForget @@ -20,9 +19,11 @@ import arrow.fx.coroutines.guaranteeCase import arrow.fx.coroutines.stream.concurrent.Signal import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup +import kotlinx.coroutines.delay import java.util.concurrent.TimeoutException import kotlin.coroutines.CoroutineContext import kotlin.random.Random +import kotlin.time.Duration class ForStream private constructor() { companion object @@ -1447,7 +1448,7 @@ inline fun StreamOf.fix(): Stream = * Interrupts this stream after the specified duration has passed. */ fun interruptAfter(duration: Duration): Stream = - interruptWhen { Right(arrow.fx.coroutines.sleep(duration)) } + interruptWhen { Right(delay(duration)) } /** * Transforms this stream using the given `Pipe`. @@ -1478,7 +1479,7 @@ inline fun StreamOf.fix(): Stream = * A single-element `Stream` that waits for the duration `d` before emitting unit. */ fun sleep(d: Duration): Stream = - effect { arrow.fx.coroutines.sleep(d) } + effect { delay(d) } /** * Alias for `sleep(d).void`. Often used in conjunction with [append] (i.e., `sleep_(..).append { s }`) as a more diff --git a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/BracketTest.kt b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/BracketTest.kt index 682300dc5..923703544 100644 --- a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/BracketTest.kt +++ b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/BracketTest.kt @@ -8,9 +8,8 @@ import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.ForkAndForget import arrow.fx.coroutines.Promise import arrow.fx.coroutines.leftException -import arrow.fx.coroutines.milliseconds +import kotlin.time.milliseconds import arrow.fx.coroutines.parTupledN -import arrow.fx.coroutines.sleep import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeInstanceOf @@ -19,6 +18,7 @@ import io.kotest.property.arbitrary.bool import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.string +import kotlinx.coroutines.delay class BracketTest : StreamSpec(spec = { @@ -243,7 +243,7 @@ class BracketTest : StreamSpec(spec = { exit.complete(ex) throw e }).flatMap { Stream.never() } - .interruptWhen { Right(sleep(50.milliseconds)) } + .interruptWhen { Right(delay(50.milliseconds)) } .drain() } shouldBe e @@ -346,7 +346,7 @@ class BracketTest : StreamSpec(spec = { ) } - parTupledN({ latch.get() }, { sleep(50.milliseconds) }) + parTupledN({ latch.get() }, { delay(50.milliseconds) }) f.cancel() diff --git a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/CallbackTest.kt b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/CallbackTest.kt index 35856d601..e869a28bb 100644 --- a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/CallbackTest.kt +++ b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/CallbackTest.kt @@ -11,13 +11,13 @@ import arrow.fx.coroutines.UnsafePromise import arrow.fx.coroutines.cancelBoundary import arrow.fx.coroutines.milliseconds import arrow.fx.coroutines.parTupledN -import arrow.fx.coroutines.sleep import arrow.fx.coroutines.startCoroutineCancellable import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.map +import kotlinx.coroutines.delay class CallbackTest : StreamSpec(iterations = 250, spec = { @@ -93,7 +93,7 @@ class CallbackTest : StreamSpec(iterations = 250, spec = { Stream.callback { emit(1) - sleep(500.milliseconds) + delay(500.milliseconds.millis) emit(2) ref.set(true) end() @@ -145,7 +145,7 @@ class CallbackTest : StreamSpec(iterations = 250, spec = { ) } - parTupledN({ latch.get() }, { sleep(20.milliseconds) }) + parTupledN({ latch.get() }, { delay(20.milliseconds.millis) }) f.cancel() @@ -180,7 +180,7 @@ class CallbackTest : StreamSpec(iterations = 250, spec = { ForkConnected { cancel.invoke() } // Let cancel schedule - sleep(10.milliseconds) + delay(10.milliseconds.millis) start.complete(Unit) // Continue cancellableF @@ -213,7 +213,7 @@ private suspend fun countToCallback( arrow.fx.coroutines.repeat(Schedule.recurs(iterations)) { i += 1 cb(map(i)) - sleep(500.milliseconds) + delay(500.milliseconds.millis) } onEnd() } diff --git a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/ConcurrentlyTest.kt b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/ConcurrentlyTest.kt index 4a2a51fea..fd51e83f5 100644 --- a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/ConcurrentlyTest.kt +++ b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/ConcurrentlyTest.kt @@ -5,13 +5,13 @@ import arrow.fx.coroutines.Atomic import arrow.fx.coroutines.Promise import arrow.fx.coroutines.Semaphore import arrow.fx.coroutines.leftException -import arrow.fx.coroutines.milliseconds +import kotlin.time.milliseconds import arrow.fx.coroutines.never -import arrow.fx.coroutines.sleep import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int +import kotlinx.coroutines.delay class ConcurrentlyTest : StreamSpec(spec = { @@ -38,7 +38,7 @@ class ConcurrentlyTest : StreamSpec(spec = { "when primary stream fails, overall stream fails and background stream is terminated" { checkAll(Arb.throwable()) { e -> val semaphore = Semaphore(0) - val bg = Stream.effect { sleep(50.milliseconds) }.repeat().onFinalize { semaphore.release() } + val bg = Stream.effect { delay(50.milliseconds) }.repeat().onFinalize { semaphore.release() } val fg = Stream.raiseError(e).delayBy(25.milliseconds) assertThrowable { @@ -53,7 +53,7 @@ class ConcurrentlyTest : StreamSpec(spec = { checkAll(Arb.stream(Arb.int())) { s -> val semaphore = Semaphore(0) - val bg = Stream.effect { sleep(50.milliseconds) }.repeat().onFinalize { semaphore.release() } + val bg = Stream.effect { delay(50.milliseconds) }.repeat().onFinalize { semaphore.release() } val fg = s.delayBy(25.milliseconds) fg.concurrently(bg) @@ -82,7 +82,7 @@ class ConcurrentlyTest : StreamSpec(spec = { val runner = Stream.bracket( { runnerRun.set(true) }, { - sleep(100.milliseconds) // assure this inner finalizer always take longer run than `outer` + delay(100.milliseconds) // assure this inner finalizer always take longer run than `outer` finRef.update { it + "Inner" } // signal finalizer invoked throw e // signal a failure }).flatMap { // flag the concurrently had chance to start, as if the `s` will be empty `runner` may not be evaluated at all. diff --git a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/InterruptionTest.kt b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/InterruptionTest.kt index c6125e287..7f8ddf5cc 100644 --- a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/InterruptionTest.kt +++ b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/InterruptionTest.kt @@ -9,17 +9,17 @@ import arrow.fx.coroutines.Promise import arrow.fx.coroutines.ForkAndForget import arrow.fx.coroutines.guaranteeCase import arrow.fx.coroutines.guarantee -import arrow.fx.coroutines.timeOutOrNull import arrow.fx.coroutines.Semaphore import arrow.fx.coroutines.ExitCase -import arrow.fx.coroutines.milliseconds -import arrow.fx.coroutines.sleep +import kotlin.time.milliseconds import arrow.fx.coroutines.never import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.property.Arb import io.kotest.property.arbitrary.int +import kotlinx.coroutines.delay +import kotlinx.coroutines.withTimeoutOrNull class InterruptionTest : StreamSpec(spec = { "can cancel a hung effect" - { @@ -31,7 +31,7 @@ class InterruptionTest : StreamSpec(spec = { s.append { Stream(1) } // Make sure is not empty .effectMap { guaranteeCase({ latch.complete(Unit); never() }) { ex -> exit.complete(ex) } - }.interruptWhen { Right(latch.get().also { sleep(20.milliseconds) }) } + }.interruptWhen { Right(latch.get().also { delay(20.milliseconds) }) } .toList() } @@ -44,7 +44,7 @@ class InterruptionTest : StreamSpec(spec = { "can interrupt a hung effect" - { checkAll(Arb.stream(Arb.int())) { s -> s.effectMap { never() } - .interruptWhen { Right(sleep(20.milliseconds)) } + .interruptWhen { Right(delay(20.milliseconds)) } .toList() shouldBe emptyList() } } @@ -65,7 +65,7 @@ class InterruptionTest : StreamSpec(spec = { "constant stream" - { checkAll(Arb.int()) { i -> Stream.constant(i) - .interruptWhen { Right(sleep(20.milliseconds)) } + .interruptWhen { Right(delay(20.milliseconds)) } .drain() // Finishes and gets interrupted } } @@ -73,7 +73,7 @@ class InterruptionTest : StreamSpec(spec = { "constant stream with a flatMap" - { checkAll(Arb.int()) { i -> Stream.constant(i) - .interruptWhen { Right(sleep(20.milliseconds)) } + .interruptWhen { Right(delay(20.milliseconds)) } .flatMap { Stream(1) } .drain() } @@ -84,7 +84,7 @@ class InterruptionTest : StreamSpec(spec = { Stream(i).flatMap { i -> Stream(i).append { loop(i + 1) } } loop(0) - .interruptWhen { Right(sleep(20.milliseconds)) } + .interruptWhen { Right(delay(20.milliseconds)) } .drain() } @@ -93,7 +93,7 @@ class InterruptionTest : StreamSpec(spec = { Stream.effect { Unit }.flatMap { loop() } loop() - .interruptWhen { Right(sleep(20.milliseconds)) } + .interruptWhen { Right(delay(20.milliseconds)) } .drain() } @@ -102,19 +102,19 @@ class InterruptionTest : StreamSpec(spec = { Stream(Unit).flatMap { loop() } loop() - .interruptWhen { Right(sleep(20.milliseconds)) } + .interruptWhen { Right(delay(20.milliseconds)) } .drain() } "effect stream" - { Stream.effect { Unit }.repeat() - .interruptWhen { Right(sleep(20.milliseconds)) } + .interruptWhen { Right(delay(20.milliseconds)) } .drain() } "Constant drained stream" - { Stream.constant(true) - .interruptWhen { Right(sleep(20.milliseconds)) } + .interruptWhen { Right(delay(20.milliseconds)) } .drain() } @@ -148,7 +148,7 @@ class InterruptionTest : StreamSpec(spec = { "stream that never terminates in flatMap" - { checkAll(Arb.stream(Arb.int())) { s -> - s.interruptWhen { Right(sleep(20.milliseconds)) } + s.interruptWhen { Right(delay(20.milliseconds)) } .flatMap { Stream.never() } .toList() shouldBe emptyList() } @@ -160,7 +160,7 @@ class InterruptionTest : StreamSpec(spec = { Stream.effect { Semaphore(0) }.flatMap { semaphore -> Stream(1) .append { s } - .interruptWhen { sleep(20.milliseconds); Either.Left(e) } + .interruptWhen { delay(20.milliseconds); Either.Left(e) } .flatMap { Stream.effect_ { semaphore.acquire() } } }.toList() } shouldBe Either.Left(e) @@ -169,7 +169,7 @@ class InterruptionTest : StreamSpec(spec = { "resume on append" - { Stream.never() - .interruptWhen { Right(sleep(20.milliseconds)) } + .interruptWhen { Right(delay(20.milliseconds)) } .append { Stream(5) } .toList() shouldBe listOf(5) } @@ -178,7 +178,7 @@ class InterruptionTest : StreamSpec(spec = { checkAll(Arb.stream(Arb.int())) { s -> val expected = s.toList() - s.interruptWhen { Right(sleep(20.milliseconds)) } + s.interruptWhen { Right(delay(20.milliseconds)) } .effectMap { never() } .void() .append { s } @@ -190,7 +190,7 @@ class InterruptionTest : StreamSpec(spec = { checkAll(Arb.stream(Arb.int())) { s -> val expected = s.toList() - s.interruptWhen { Right(sleep(20.milliseconds)) } + s.interruptWhen { Right(delay(20.milliseconds)) } .effectMap { never>() } .append { s.map { Some(it) } } .filterOption() @@ -203,7 +203,7 @@ class InterruptionTest : StreamSpec(spec = { val expected = s.toList() s.append { Stream(1) } - .interruptWhen { Right(sleep(50.milliseconds)) } + .interruptWhen { Right(delay(50.milliseconds)) } .map { None } .append { s.map { Some(it) } } .flatMap { @@ -250,7 +250,7 @@ class InterruptionTest : StreamSpec(spec = { "resume on append with pull" - { Stream(1) .unchunk() - .interruptWhen { Right(sleep(20.milliseconds)) } + .interruptWhen { Right(delay(20.milliseconds)) } .asPull() .unconsOrNull() .flatMap { uncons -> @@ -267,7 +267,7 @@ class InterruptionTest : StreamSpec(spec = { "resume with append after evalMap interruption" - { Stream(1) - .interruptWhen { Right(sleep(20.milliseconds)) } + .interruptWhen { Right(delay(20.milliseconds)) } .effectMap { never() } .append { Stream(5) } .toList() shouldBe listOf(5) @@ -276,7 +276,7 @@ class InterruptionTest : StreamSpec(spec = { "interrupted effect is cancelled" - { val latch = Promise() - timeOutOrNull(500.milliseconds) { + withTimeoutOrNull(500.milliseconds) { Stream.effect { guarantee({ latch.get() }) { latch.complete(Unit) } } .interruptAfter(50.milliseconds) .drain() @@ -290,7 +290,7 @@ class InterruptionTest : StreamSpec(spec = { io.kotest.property.checkAll(500, Arb.stream(Arb.int())) { s -> val expected = s.toList() - s.interruptWhen { Right(sleep(50.milliseconds)) } + s.interruptWhen { Right(delay(50.milliseconds)) } .map { None } .append { s.map { Option(it) } } .interruptWhen { Right(never()) } diff --git a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/ParJoinTest.kt b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/ParJoinTest.kt index 185749c21..74fefa278 100644 --- a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/ParJoinTest.kt +++ b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/ParJoinTest.kt @@ -5,7 +5,6 @@ import arrow.fx.coroutines.Atomic import arrow.fx.coroutines.Promise import arrow.fx.coroutines.leftException import arrow.fx.coroutines.milliseconds -import arrow.fx.coroutines.sleep import arrow.fx.coroutines.never import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder import io.kotest.matchers.should @@ -14,6 +13,7 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.bool import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.positiveInts +import kotlinx.coroutines.delay import java.lang.RuntimeException class ParJoinTest : StreamSpec(spec = { @@ -75,7 +75,7 @@ class ParJoinTest : StreamSpec(spec = { // this introduces delay and failure based on bias of the test suspend fun finalizer(idx: Int): Unit = if (idx == biasIdx) { - sleep(50.milliseconds) + delay(50.milliseconds.millis) finalizerRef.update { it + "Inner $idx" } throw err } else finalizerRef.update { it + "Inner $idx" } diff --git a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/concurrent/QueueTest.kt b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/concurrent/QueueTest.kt index bc6a83206..e2b406ebe 100644 --- a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/concurrent/QueueTest.kt +++ b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/concurrent/QueueTest.kt @@ -5,9 +5,8 @@ import arrow.fx.coroutines.ForkAndForget import arrow.fx.coroutines.ForkConnected import arrow.fx.coroutines.Promise import arrow.fx.coroutines.stream.StreamSpec -import arrow.fx.coroutines.milliseconds -import arrow.fx.coroutines.seconds -import arrow.fx.coroutines.sleep +import kotlin.time.milliseconds +import kotlin.time.seconds import arrow.fx.coroutines.stream.Stream import arrow.fx.coroutines.stream.append import arrow.fx.coroutines.stream.drain @@ -15,13 +14,14 @@ import arrow.fx.coroutines.stream.noneTerminate import arrow.fx.coroutines.stream.parJoinUnbounded import arrow.fx.coroutines.stream.terminateOnNone import arrow.fx.coroutines.stream.toList -import arrow.fx.coroutines.timeOutOrNull import io.kotest.assertions.assertSoftly import io.kotest.matchers.ints.shouldBeLessThan import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.positiveInts +import kotlinx.coroutines.delay +import kotlinx.coroutines.withTimeoutOrNull import kotlin.math.max class QueueTest : StreamSpec(spec = { @@ -185,7 +185,7 @@ class QueueTest : StreamSpec(spec = { "cancel" { val q = Queue.unbounded() - timeOutOrNull(100.milliseconds) { + withTimeoutOrNull(100.milliseconds) { q.dequeue1() } shouldBe null q.enqueue1(1) @@ -255,7 +255,7 @@ class QueueTest : StreamSpec(spec = { "Queue.bounded(0) with outstanding taker cannot offer" { val q = Queue.bounded(0) val taker = ForkConnected { q.dequeue1() } - sleep(1.seconds) + delay(1.seconds) q.tryOffer1(1) shouldBe false taker.cancel() } @@ -281,7 +281,7 @@ class QueueTest : StreamSpec(spec = { "Queue.synchronous with outstanding taker can tryOffer1" { val q = Queue.synchronous() ForkConnected { q.dequeue1() } - sleep(1.seconds) + delay(1.seconds) q.tryOffer1(1) shouldBe true } }) diff --git a/arrow-fx-coroutines-test/build.gradle b/arrow-fx-coroutines-test/build.gradle index 6c520d69c..e3a87ff59 100644 --- a/arrow-fx-coroutines-test/build.gradle +++ b/arrow-fx-coroutines-test/build.gradle @@ -1,13 +1,5 @@ -plugins { - id "org.jetbrains.kotlin.jvm" - id "org.jlleitschuh.gradle.ktlint" -} - apply plugin: 'kotlinx-atomicfu' -apply from: "$SUB_PROJECT" -apply from: "$DOC_CREATION" - dependencies { api "io.arrow-kt:arrow-core:$VERSION_NAME" api project(":arrow-fx-coroutines") diff --git a/arrow-fx-coroutines/build.gradle b/arrow-fx-coroutines/build.gradle index b8270a8e7..a6f55bfb7 100644 --- a/arrow-fx-coroutines/build.gradle +++ b/arrow-fx-coroutines/build.gradle @@ -1,13 +1,5 @@ -plugins { - id "org.jetbrains.kotlin.jvm" - id "org.jlleitschuh.gradle.ktlint" -} - apply plugin: 'kotlinx-atomicfu' -apply from: "$SUB_PROJECT" -apply from: "$DOC_CREATION" - dependencies { api "io.arrow-kt:arrow-core:$VERSION_NAME" implementation project(":arrow-fx-suspend-connection") diff --git a/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Schedule.kt b/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Schedule.kt index 9ad5fb094..ecbcec1df 100644 --- a/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Schedule.kt +++ b/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Schedule.kt @@ -6,6 +6,7 @@ import arrow.core.identity import arrow.core.left import arrow.core.right import arrow.fx.coroutines.Schedule.ScheduleImpl +import kotlinx.coroutines.delay import kotlin.math.max import kotlin.math.min import kotlin.math.pow @@ -775,7 +776,7 @@ suspend fun repeatOrElseEither( val step = schedule.update(a, state) if (!step.cont) return Either.Right(step.finish.value()) else { - sleep(step.delay) + delay(step.delay.millis) // Set state before looping again last = { step.finish.value() } @@ -829,7 +830,7 @@ suspend fun retryOrElseEither( dec = schedule.update(e, state) state = dec.state - if (dec.cont) sleep(dec.delay) + if (dec.cont) delay(dec.delay.millis) else return Either.Left(orElse(e.nonFatalOrThrow(), dec.finish.value())) } } diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/BracketCaseTest.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/BracketCaseTest.kt index 8a2954137..14797fe1f 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/BracketCaseTest.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/BracketCaseTest.kt @@ -9,6 +9,7 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.long import io.kotest.property.checkAll +import kotlinx.coroutines.delay import kotlinx.coroutines.test.runBlockingTest import kotlin.time.ExperimentalTime @@ -21,7 +22,7 @@ class BracketCaseTest : ArrowFxSpec(spec = { val start = currentTime val n = timeOutOrNull(a.milliseconds) { - uncancellable { sleep(b.milliseconds) } + uncancellable { delay(b.milliseconds.millis) } } val duration = currentTime - start diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancelBoundary.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancelBoundary.kt index 4cfc82952..5978433ef 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancelBoundary.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancelBoundary.kt @@ -2,6 +2,7 @@ package arrow.fx.coroutines import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.types.shouldBeInstanceOf +import kotlinx.coroutines.delay class CancelBoundary : StringSpec({ @@ -23,6 +24,6 @@ class CancelBoundary : StringSpec({ latch.get() f.cancel() exit.get().shouldBeInstanceOf() - sleep(1.seconds) + delay(1.seconds.millis) } }) diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancellableF.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancellableF.kt index 1dd84849b..c7881db9d 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancellableF.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancellableF.kt @@ -6,6 +6,7 @@ import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.checkAll +import kotlinx.coroutines.delay import kotlinx.coroutines.launch class CancellableF : ArrowFxSpec(spec = { @@ -103,7 +104,7 @@ class CancellableF : ArrowFxSpec(spec = { ForkConnected { cancel.invoke() } // Let cancel schedule - sleep(10.milliseconds) + delay(10.milliseconds.millis) start.complete(Unit) // Continue cancellableF diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CircuitBreakerTest.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CircuitBreakerTest.kt index 8417f7525..4a22a5f2d 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CircuitBreakerTest.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CircuitBreakerTest.kt @@ -4,6 +4,7 @@ import arrow.core.Either import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe +import kotlinx.coroutines.delay import java.lang.RuntimeException class CircuitBreakerTest : ArrowFxSpec(spec = { @@ -107,7 +108,7 @@ class CircuitBreakerTest : ArrowFxSpec(spec = { } // After resetTimeout passes, CB should still be Open, and we should be able to reset to Closed. - sleep(resetTimeout + 10.milliseconds) + delay((resetTimeout + 10.milliseconds).millis) when (val s = cb.state()) { is CircuitBreaker.State.Open -> { @@ -186,7 +187,7 @@ class CircuitBreakerTest : ArrowFxSpec(spec = { } // After resetTimeout passes, CB should still be Open, and we should be able to reset to Closed. - sleep(resetTimeout + 10.milliseconds) + delay((resetTimeout + 10.milliseconds).millis) when (val s = cb.state()) { is CircuitBreaker.State.Open -> { diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ConcurrentVarTest.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ConcurrentVarTest.kt index 6b762b164..6fe8cbfd4 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ConcurrentVarTest.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ConcurrentVarTest.kt @@ -4,6 +4,7 @@ import arrow.core.Either import arrow.core.toT import io.kotest.assertions.fail import io.kotest.matchers.shouldBe +import kotlinx.coroutines.delay import kotlin.time.ExperimentalTime @ExperimentalTime @@ -192,7 +193,7 @@ class ConcurrentVarTest : ArrowFxSpec(spec = { ForkAndForget { mVar.put(1) } val p2 = ForkAndForget { mVar.put(2) } ForkAndForget { mVar.put(3) } - sleep(10.milliseconds) // Give put callbacks a chance to register + delay(10.milliseconds.millis) // Give put callbacks a chance to register p2.cancel() mVar.take() val r1 = mVar.take() @@ -205,7 +206,7 @@ class ConcurrentVarTest : ArrowFxSpec(spec = { val t1 = ForkAndForget { mVar.take() } val t2 = ForkAndForget { mVar.take() } val t3 = ForkAndForget { mVar.take() } - sleep(10.milliseconds) // Give take callbacks a chance to register + delay(10.milliseconds.millis) // Give take callbacks a chance to register t2.cancel() mVar.put(1) mVar.put(3) @@ -221,10 +222,10 @@ class ConcurrentVarTest : ArrowFxSpec(spec = { mVar.read() finished.complete(1) } - sleep(100.milliseconds) // Give read callback a chance to register + delay(100.milliseconds.millis) // Give read callback a chance to register fiber.cancel() mVar.put(10) - val fallback = suspend { sleep(200.milliseconds); 0 } + val fallback = suspend { delay(200.milliseconds.millis); 0 } raceN(finished::get, fallback) shouldBe Either.Right(0) } @@ -251,7 +252,7 @@ class ConcurrentVarTest : ArrowFxSpec(spec = { finished.complete(Unit) } } - sleep(100.milliseconds) + delay(100.milliseconds.millis) fiber.cancel() started.tryGet() shouldBe 10 finished.tryGet() shouldBe null @@ -282,7 +283,7 @@ class ConcurrentVarTest : ArrowFxSpec(spec = { it + 1 } } - sleep(10.milliseconds) + delay(10.milliseconds.millis) fiber.cancel() started.get() shouldBe 10 finished.tryGet() shouldBe null diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/EnvironmentTest.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/EnvironmentTest.kt index d51d876a6..063b19597 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/EnvironmentTest.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/EnvironmentTest.kt @@ -6,6 +6,7 @@ import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.checkAll +import kotlinx.coroutines.delay class EnvironmentTest : StringSpec({ @@ -73,7 +74,7 @@ class EnvironmentTest : StringSpec({ } tailrec suspend fun sleeper(): Unit { - sleep(1.milliseconds) + delay(1.milliseconds.millis) sleeper() } diff --git a/arrow-fx-stm/build.gradle b/arrow-fx-stm/build.gradle index 313b90d53..23702daae 100644 --- a/arrow-fx-stm/build.gradle +++ b/arrow-fx-stm/build.gradle @@ -1,13 +1,5 @@ -plugins { - id "org.jetbrains.kotlin.jvm" - id "org.jlleitschuh.gradle.ktlint" -} - apply plugin: 'kotlinx-atomicfu' -apply from: "$SUB_PROJECT" -apply from: "$DOC_CREATION" - dependencies { api "io.arrow-kt:arrow-core:$VERSION_NAME" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLINX_COROUTINES_VERSION" diff --git a/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/STMTest.kt b/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/STMTest.kt index 0c6f11d36..7fbe75142 100644 --- a/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/STMTest.kt +++ b/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/STMTest.kt @@ -7,7 +7,6 @@ import arrow.fx.coroutines.microseconds import arrow.fx.coroutines.milliseconds import arrow.fx.coroutines.parMapN import arrow.fx.coroutines.parTraverse -import arrow.fx.coroutines.sleep import arrow.fx.coroutines.timeOutOrNull import arrow.fx.stm.internal.BlockedIndefinitely import io.kotest.assertions.throwables.shouldThrow @@ -17,6 +16,7 @@ import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.bool import io.kotest.property.arbitrary.int +import kotlinx.coroutines.delay class STMTest : ArrowFxSpec(spec = { "no-effects" { @@ -85,7 +85,7 @@ class STMTest : ArrowFxSpec(spec = { "a suspended transaction will resume if a variable changes" { val tv = TVar.new(0) val f = ForkConnected { - sleep(500.milliseconds) + delay(500.milliseconds.millis) atomically { tv.modify { it + 1 } } } atomically { @@ -101,11 +101,11 @@ class STMTest : ArrowFxSpec(spec = { val v2 = TVar.new(0) val v3 = TVar.new(0) val f = ForkConnected { - sleep(500.milliseconds) + delay(500.milliseconds.millis) atomically { v1.modify { it + 1 } } - sleep(500.milliseconds) + delay(500.milliseconds.millis) atomically { v2.modify { it + 1 } } - sleep(500.milliseconds) + delay(500.milliseconds.millis) atomically { v3.modify { it + 1 } } } atomically { @@ -150,7 +150,7 @@ class STMTest : ArrowFxSpec(spec = { checkAll { val tv = TVar.new(0) val f = ForkConnected { - sleep(10.microseconds) + delay(10.microseconds.millis) atomically { tv.modify { it + 1 } } } atomically { @@ -221,7 +221,7 @@ class STMTest : ArrowFxSpec(spec = { } }, { atomically { acc1.modify { it - 60 } } - sleep(20.milliseconds) + delay(20.milliseconds.millis) atomically { acc1.modify { it + 60 } } }, { _, _ -> Unit }) acc1.unsafeRead() shouldBeExactly 50 diff --git a/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/TVarTest.kt b/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/TVarTest.kt index c51112da6..7e7fbad9d 100644 --- a/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/TVarTest.kt +++ b/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/TVarTest.kt @@ -3,12 +3,12 @@ package arrow.fx.stm import arrow.fx.coroutines.ArrowFxSpec import arrow.fx.coroutines.milliseconds import arrow.fx.coroutines.raceN -import arrow.fx.coroutines.sleep import arrow.fx.stm.internal.STMFrame import io.kotest.matchers.ints.shouldBeExactly import io.kotest.matchers.shouldBe import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay import kotlinx.coroutines.launch class TVarTest : ArrowFxSpec(spec = { @@ -27,14 +27,14 @@ class TVarTest : ArrowFxSpec(spec = { val sleepWon = CompletableDeferred() val job1 = launch { - raceN(Dispatchers.IO, { sleep(50.milliseconds); sleepWon.complete(Unit) }, { tv.unsafeRead() }) + raceN(Dispatchers.IO, { delay(50.milliseconds.millis); sleepWon.complete(Unit) }, { tv.unsafeRead() }) .fold({}, { throw IllegalStateException("Lock did not lock!") }) } sleepWon.await() val sleepWon2 = CompletableDeferred() val job2 = launch { - raceN(Dispatchers.IO, { sleep(50.milliseconds); sleepWon2.complete(Unit) }, { tv.lock(STMFrame()) }) + raceN(Dispatchers.IO, { delay(50.milliseconds.millis); sleepWon2.complete(Unit) }, { tv.lock(STMFrame()) }) .fold({}, { throw IllegalStateException("Lock did not lock!") }) } sleepWon2.await() @@ -52,7 +52,7 @@ class TVarTest : ArrowFxSpec(spec = { val sleepWon = CompletableDeferred() val job1 = launch { - raceN(Dispatchers.IO, { sleep(50.milliseconds); sleepWon.complete(Unit) }, { tv.unsafeRead() }) + raceN(Dispatchers.IO, { delay(50.milliseconds.millis); sleepWon.complete(Unit) }, { tv.unsafeRead() }) .fold({}, { throw IllegalStateException("Lock did not lock!") }) } sleepWon.await() @@ -62,7 +62,7 @@ class TVarTest : ArrowFxSpec(spec = { val sleepWon2 = CompletableDeferred() val job2 = launch { - raceN(Dispatchers.IO, { sleep(50.milliseconds); sleepWon2.complete(Unit) }, { tv.unsafeRead() }) + raceN(Dispatchers.IO, { delay(50.milliseconds.millis); sleepWon2.complete(Unit) }, { tv.unsafeRead() }) .fold({}, { throw IllegalStateException("Lock did not lock!") }) } sleepWon2.await() diff --git a/arrow-fx/src/test/kotlin/arrow/fx/IOTest.kt b/arrow-fx/src/test/kotlin/arrow/fx/IOTest.kt index 53ca17e29..9aec50a9f 100644 --- a/arrow-fx/src/test/kotlin/arrow/fx/IOTest.kt +++ b/arrow-fx/src/test/kotlin/arrow/fx/IOTest.kt @@ -14,8 +14,6 @@ import arrow.core.test.concurrency.SideEffect import arrow.core.test.laws.SemigroupKLaws import arrow.fx.IO.Companion.just import arrow.fx.coroutines.Environment -import arrow.fx.coroutines.timeOutOrNull -import arrow.fx.coroutines.seconds as cSeconds import arrow.fx.extensions.fx import arrow.fx.extensions.io.applicative.applicative import arrow.fx.extensions.io.async.async @@ -29,21 +27,25 @@ import arrow.fx.extensions.timer import arrow.fx.extensions.toIO import arrow.fx.internal.parMap2 import arrow.fx.internal.parMap3 -import arrow.fx.typeclasses.ExitCase -import arrow.fx.typeclasses.milliseconds -import arrow.fx.typeclasses.seconds import arrow.fx.test.eq.eqK import arrow.fx.test.generators.genK import arrow.fx.test.laws.ConcurrentLaws +import arrow.fx.typeclasses.ExitCase +import arrow.fx.typeclasses.milliseconds +import arrow.fx.typeclasses.seconds import io.kotlintest.fail import io.kotlintest.matchers.types.shouldBeInstanceOf import io.kotlintest.properties.Gen import io.kotlintest.shouldBe import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.newSingleThreadContext +import kotlinx.coroutines.withTimeoutOrNull import kotlin.coroutines.AbstractCoroutineContextElement import kotlin.coroutines.EmptyCoroutineContext +import kotlin.time.ExperimentalTime +import kotlin.time.seconds as kSeconds +@ExperimentalTime @kotlinx.coroutines.ObsoleteCoroutinesApi class IOTest : ArrowFxSpec() { @@ -54,7 +56,8 @@ class IOTest : ArrowFxSpec() { init { testLaws( SemigroupKLaws.laws(IO.semigroupK(), IO.genK(), IO.eqK()), - ConcurrentLaws.laws(IO.concurrent(), IO.timer(), IO.functor(), IO.applicative(), IO.monad(), IO.genK(), IO.eqK())) + ConcurrentLaws.laws(IO.concurrent(), IO.timer(), IO.functor(), IO.applicative(), IO.monad(), IO.genK(), IO.eqK()) + ) "should defer evaluation until run" { var run = false @@ -427,8 +430,10 @@ class IOTest : ArrowFxSpec() { } val result = - IO.parMapN(all, - makePar(6), makePar(3), makePar(2), makePar(4), makePar(1), makePar(5)) { six, tree, two, four, one, five -> listOf(six, tree, two, four, one, five) } + IO.parMapN( + all, + makePar(6), makePar(3), makePar(2), makePar(4), makePar(1), makePar(5) + ) { six, tree, two, four, one, five -> listOf(six, tree, two, four, one, five) } .unsafeRunSync() result shouldBe listOf(6L, 3, 2, 4, 1, 5) @@ -450,7 +455,8 @@ class IOTest : ArrowFxSpec() { val result = IO.parMapN(all, - makePar(6), just(1L).order(), makePar(4), IO.defer { just(2L) }.order(), makePar(5), IO { 3L }.order()) { six, one, four, two, five, three -> listOf(six, one, four, two, five, three) } + makePar(6), just(1L).order(), makePar(4), IO.defer { just(2L) }.order(), makePar(5), IO { 3L }.order() + ) { six, one, four, two, five, three -> listOf(six, one, four, two, five, three) } .unsafeRunSync() result shouldBe listOf(6L, 1, 4, 2, 5, 3) @@ -647,19 +653,19 @@ class IOTest : ArrowFxSpec() { "forked pair race should run" { IO.fx { dispatchers().io().raceN( - timer().sleep(10.seconds).followedBy(effect { 1 }), - effect { 3 } - ).fork().invoke().join().invoke() + timer().sleep(10.seconds).followedBy(effect { 1 }), + effect { 3 } + ).fork().invoke().join().invoke() }.unsafeRunSync() shouldBe 3.right() } "forked triple race should run" { IO.fx { dispatchers().io().raceN( - timer().sleep(10.seconds).followedBy(effect { 1 }), - timer().sleep(10.seconds).followedBy(effect { 3 }), - effect { 2 } - ).fork().invoke().join().invoke() + timer().sleep(10.seconds).followedBy(effect { 1 }), + timer().sleep(10.seconds).followedBy(effect { 3 }), + effect { 2 } + ).fork().invoke().join().invoke() }.unsafeRunSync() shouldBe Race3.Third(2) } @@ -791,9 +797,9 @@ class IOTest : ArrowFxSpec() { use = { IO.never } ).suspended() } - arrow.fx.coroutines.sleep(2.cSeconds) + delay(2.kSeconds) disp.invoke() - timeOutOrNull(5.cSeconds) { p.get() } shouldBe ExitCase.Cancelled + withTimeoutOrNull(5.kSeconds) { p.get() } shouldBe ExitCase.Cancelled } } } diff --git a/build.gradle b/build.gradle index 2b67ba7bf..f91f94ec2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,51 +1,77 @@ buildscript { - apply from: "$COMMON_SETUP" - repositories { - gradlePluginPortal() - mavenCentral() - google() - } - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION" - classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$ATOMICFU_VERSION" - classpath "com.android.tools.build:gradle:$ANDROID_TOOLS_BUILD_PLUGIN_VERSION" - } + apply from: "$COMMON_SETUP" + repositories { + gradlePluginPortal() + mavenCentral() + google() + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION" + classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$ATOMICFU_VERSION" + classpath "com.android.tools.build:gradle:$ANDROID_TOOLS_BUILD_PLUGIN_VERSION" + } } plugins { - id "org.jetbrains.dokka" version "$DOKKA_VERSION" apply false - id "org.jlleitschuh.gradle.ktlint" version "$KTLINT_GRADLE_VERSION" apply false - id "ru.vyarus.animalsniffer" version "$ANIMALS_SNIFFER_VERSION" apply false + id "org.jetbrains.dokka" version "$DOKKA_VERSION" apply false + id "org.jlleitschuh.gradle.ktlint" version "$KTLINT_GRADLE_VERSION" apply false + id "ru.vyarus.animalsniffer" version "$ANIMALS_SNIFFER_VERSION" apply false } apply from: "$ROOT_PROJECT" // -- Artifacts publication configure(subprojects - - project("arrow-benchmarks-fx") - - project("arrow-benchmarks-fx:arrow-scala-benchmarks") - - project("arrow-benchmarks-fx:arrow-kio-benchmarks") + - project("arrow-benchmarks-fx") + - project("arrow-benchmarks-fx:arrow-scala-benchmarks") + - project("arrow-benchmarks-fx:arrow-kio-benchmarks") ) { - apply from: "$PUBLICATION" + apply from: "$PUBLICATION" } // -- Gradle Animal Sniffer Plugin: https://github.com/xvik/gradle-animalsniffer-plugin configure(subprojects - - project("arrow-benchmarks-fx") - - project("arrow-benchmarks-fx:arrow-scala-benchmarks") - - project("arrow-benchmarks-fx:arrow-kio-benchmarks") - - project("arrow-fx-coroutines") - - project("arrow-fx-reactor") + - project("arrow-benchmarks-fx") + - project("arrow-benchmarks-fx:arrow-scala-benchmarks") + - project("arrow-benchmarks-fx:arrow-kio-benchmarks") + - project("arrow-fx-coroutines") + - project("arrow-fx-reactor") ) { - apply plugin: 'ru.vyarus.animalsniffer' - apply plugin: 'java' + apply plugin: 'ru.vyarus.animalsniffer' + apply plugin: 'java' - animalsniffer { // Ignore tests - sourceSets = [sourceSets.main] - ignore 'java.lang.*' - } + animalsniffer { // Ignore tests + sourceSets = [sourceSets.main] + ignore 'java.lang.*' + } + + dependencies { + signature 'net.sf.androidscents.signature:android-api-level-21:5.0.1_r2@signature' + } +} - dependencies { - signature 'net.sf.androidscents.signature:android-api-level-21:5.0.1_r2@signature' +configure( + [project("arrow-fx-coroutines"), + project("arrow-fx-coroutines-kotlinx-coroutines"), + project("arrow-fx-coroutines-test"), + project("arrow-fx-coroutines-stream"), + project("arrow-fx-stm")] +) { + apply plugin: "org.jetbrains.kotlin.jvm" + apply plugin: "org.jlleitschuh.gradle.ktlint" + + apply from: "$SUB_PROJECT" + apply from: "$DOC_CREATION" + + // usage of kotlin.time + compileKotlin { + kotlinOptions { + freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"] + } + } + compileTestKotlin { + kotlinOptions { + freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"] } + } } From 8937cc733137a1bcff7af127c3e3201dd7801a27 Mon Sep 17 00:00:00 2001 From: i-walker <46971368+i-walker@users.noreply.github.com> Date: Wed, 23 Dec 2020 12:50:14 +0100 Subject: [PATCH 2/3] resolve CI error building the project and further replacements --- arrow-fx-coroutines-stream/build.gradle | 20 +++++++++++++++++++ .../fx/coroutines/stream/CallbackTest.kt | 10 +++++----- .../arrow/fx/coroutines/stream/ParJoinTest.kt | 4 ++-- .../arrow/fx/coroutines/stream/StreamTest.kt | 6 +++--- arrow-fx-coroutines-test/build.gradle | 20 +++++++++++++++++++ arrow-fx-coroutines/build.gradle | 20 +++++++++++++++++++ .../arrow/fx/coroutines/BracketCaseTest.kt | 8 +++++--- .../arrow/fx/coroutines/CancelBoundary.kt | 3 ++- .../arrow/fx/coroutines/CancellableF.kt | 3 ++- .../arrow/fx/coroutines/ConcurrentVarTest.kt | 15 +++++++------- .../arrow/fx/coroutines/EnvironmentTest.kt | 3 ++- .../arrow/fx/coroutines/ParTraverseTest.kt | 4 +++- .../arrow/fx/coroutines/ScheduleTest.kt | 4 +++- .../arrow/fx/coroutines/SemaphoreTest.kt | 6 ++++-- arrow-fx-stm/build.gradle | 20 +++++++++++++++++++ .../src/test/kotlin/arrow/fx/stm/STMTest.kt | 20 +++++++++---------- .../src/test/kotlin/arrow/fx/stm/TVarTest.kt | 10 +++++----- arrow-fx/src/test/kotlin/arrow/fx/IOTest.kt | 1 + 18 files changed, 134 insertions(+), 43 deletions(-) diff --git a/arrow-fx-coroutines-stream/build.gradle b/arrow-fx-coroutines-stream/build.gradle index d530240cc..bb5938625 100644 --- a/arrow-fx-coroutines-stream/build.gradle +++ b/arrow-fx-coroutines-stream/build.gradle @@ -1,5 +1,13 @@ +plugins { + id "org.jetbrains.kotlin.jvm" + id "org.jlleitschuh.gradle.ktlint" +} + apply plugin: 'kotlinx-atomicfu' +apply from: "$SUB_PROJECT" +apply from: "$DOC_CREATION" + dependencies { api "io.arrow-kt:arrow-core:$VERSION_NAME" implementation project(":arrow-fx-coroutines") @@ -11,3 +19,15 @@ dependencies { testImplementation "io.kotest:kotest-assertions-core-jvm:$KOTEST_VERSION" // for kotest core jvm assertions testImplementation "io.kotest:kotest-property-jvm:$KOTEST_VERSION" // for kotest property test } + +// usage of kotlin.time +compileKotlin { + kotlinOptions { + freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"] + } +} +compileTestKotlin { + kotlinOptions { + freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"] + } +} \ No newline at end of file diff --git a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/CallbackTest.kt b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/CallbackTest.kt index e869a28bb..ccdcb5577 100644 --- a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/CallbackTest.kt +++ b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/CallbackTest.kt @@ -9,7 +9,7 @@ import arrow.fx.coroutines.Promise import arrow.fx.coroutines.Schedule import arrow.fx.coroutines.UnsafePromise import arrow.fx.coroutines.cancelBoundary -import arrow.fx.coroutines.milliseconds +import kotlin.time.milliseconds import arrow.fx.coroutines.parTupledN import arrow.fx.coroutines.startCoroutineCancellable import io.kotest.matchers.shouldBe @@ -93,7 +93,7 @@ class CallbackTest : StreamSpec(iterations = 250, spec = { Stream.callback { emit(1) - delay(500.milliseconds.millis) + delay(500.milliseconds) emit(2) ref.set(true) end() @@ -145,7 +145,7 @@ class CallbackTest : StreamSpec(iterations = 250, spec = { ) } - parTupledN({ latch.get() }, { delay(20.milliseconds.millis) }) + parTupledN({ latch.get() }, { delay(20.milliseconds) }) f.cancel() @@ -180,7 +180,7 @@ class CallbackTest : StreamSpec(iterations = 250, spec = { ForkConnected { cancel.invoke() } // Let cancel schedule - delay(10.milliseconds.millis) + delay(10.milliseconds) start.complete(Unit) // Continue cancellableF @@ -213,7 +213,7 @@ private suspend fun countToCallback( arrow.fx.coroutines.repeat(Schedule.recurs(iterations)) { i += 1 cb(map(i)) - delay(500.milliseconds.millis) + delay(500.milliseconds) } onEnd() } diff --git a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/ParJoinTest.kt b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/ParJoinTest.kt index 74fefa278..d2a24f830 100644 --- a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/ParJoinTest.kt +++ b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/ParJoinTest.kt @@ -4,7 +4,7 @@ import arrow.core.Either import arrow.fx.coroutines.Atomic import arrow.fx.coroutines.Promise import arrow.fx.coroutines.leftException -import arrow.fx.coroutines.milliseconds +import kotlin.time.milliseconds import arrow.fx.coroutines.never import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder import io.kotest.matchers.should @@ -75,7 +75,7 @@ class ParJoinTest : StreamSpec(spec = { // this introduces delay and failure based on bias of the test suspend fun finalizer(idx: Int): Unit = if (idx == biasIdx) { - delay(50.milliseconds.millis) + delay(50.milliseconds) finalizerRef.update { it + "Inner $idx" } throw err } else finalizerRef.update { it + "Inner $idx" } diff --git a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/StreamTest.kt b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/StreamTest.kt index fda4076dd..f18d01839 100644 --- a/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/StreamTest.kt +++ b/arrow-fx-coroutines-stream/src/test/kotlin/arrow/fx/coroutines/stream/StreamTest.kt @@ -6,8 +6,7 @@ import arrow.core.extensions.list.foldable.combineAll import arrow.core.extensions.list.foldable.foldMap import arrow.core.extensions.monoid import arrow.core.extensions.semigroup -import arrow.fx.coroutines.milliseconds -import arrow.fx.coroutines.timeOutOrNull +import kotlin.time.milliseconds import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int @@ -15,6 +14,7 @@ import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.orNull import io.kotest.property.arbitrary.positiveInts import io.kotest.property.arbitrary.set +import kotlinx.coroutines.withTimeoutOrNull import kotlin.math.absoluteValue import kotlin.math.max import kotlin.random.Random @@ -32,7 +32,7 @@ class StreamTest : StreamSpec(spec = { } "never() should timeout" { - timeOutOrNull(10.milliseconds) { + withTimeoutOrNull(10.milliseconds) { Stream.never().toList() } shouldBe null } diff --git a/arrow-fx-coroutines-test/build.gradle b/arrow-fx-coroutines-test/build.gradle index e3a87ff59..d4b70a865 100644 --- a/arrow-fx-coroutines-test/build.gradle +++ b/arrow-fx-coroutines-test/build.gradle @@ -1,5 +1,13 @@ +plugins { + id "org.jetbrains.kotlin.jvm" + id "org.jlleitschuh.gradle.ktlint" +} + apply plugin: 'kotlinx-atomicfu' +apply from: "$SUB_PROJECT" +apply from: "$DOC_CREATION" + dependencies { api "io.arrow-kt:arrow-core:$VERSION_NAME" api project(":arrow-fx-coroutines") @@ -10,3 +18,15 @@ dependencies { api "io.kotest:kotest-assertions-core-jvm:$KOTEST_VERSION" // for kotest core jvm assertions api "io.kotest:kotest-property-jvm:$KOTEST_VERSION" // for kotest property test } + +// usage of kotlin.time +compileKotlin { + kotlinOptions { + freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"] + } +} +compileTestKotlin { + kotlinOptions { + freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"] + } +} \ No newline at end of file diff --git a/arrow-fx-coroutines/build.gradle b/arrow-fx-coroutines/build.gradle index a6f55bfb7..663d7322f 100644 --- a/arrow-fx-coroutines/build.gradle +++ b/arrow-fx-coroutines/build.gradle @@ -1,5 +1,13 @@ +plugins { + id "org.jetbrains.kotlin.jvm" + id "org.jlleitschuh.gradle.ktlint" +} + apply plugin: 'kotlinx-atomicfu' +apply from: "$SUB_PROJECT" +apply from: "$DOC_CREATION" + dependencies { api "io.arrow-kt:arrow-core:$VERSION_NAME" implementation project(":arrow-fx-suspend-connection") @@ -11,3 +19,15 @@ dependencies { testImplementation "io.kotest:kotest-assertions-core-jvm:$KOTEST_VERSION" // for kotest core jvm assertions testImplementation "io.kotest:kotest-property-jvm:$KOTEST_VERSION" // for kotest property test } + +// usage of kotlin.time +compileKotlin { + kotlinOptions { + freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"] + } +} +compileTestKotlin { + kotlinOptions { + freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"] + } +} \ No newline at end of file diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/BracketCaseTest.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/BracketCaseTest.kt index 14797fe1f..bbaca6eb7 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/BracketCaseTest.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/BracketCaseTest.kt @@ -11,18 +11,20 @@ import io.kotest.property.arbitrary.long import io.kotest.property.checkAll import kotlinx.coroutines.delay import kotlinx.coroutines.test.runBlockingTest +import kotlinx.coroutines.withTimeoutOrNull import kotlin.time.ExperimentalTime +import kotlin.time.milliseconds @ExperimentalTime class BracketCaseTest : ArrowFxSpec(spec = { - "Uncancellable back pressures timeoutOrNull" { + "Uncancellable back pressures withTimeoutOrNull" { runBlockingTest { checkAll(Arb.long(50, 100), Arb.long(300, 400)) { a, b -> val start = currentTime - val n = timeOutOrNull(a.milliseconds) { - uncancellable { delay(b.milliseconds.millis) } + val n = withTimeoutOrNull(a.milliseconds) { + uncancellable { delay(b.milliseconds) } } val duration = currentTime - start diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancelBoundary.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancelBoundary.kt index 5978433ef..3eed1ad54 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancelBoundary.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancelBoundary.kt @@ -3,6 +3,7 @@ package arrow.fx.coroutines import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.types.shouldBeInstanceOf import kotlinx.coroutines.delay +import kotlin.time.seconds class CancelBoundary : StringSpec({ @@ -24,6 +25,6 @@ class CancelBoundary : StringSpec({ latch.get() f.cancel() exit.get().shouldBeInstanceOf() - delay(1.seconds.millis) + delay(1.seconds) } }) diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancellableF.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancellableF.kt index c7881db9d..47e556b71 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancellableF.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/CancellableF.kt @@ -8,6 +8,7 @@ import io.kotest.property.arbitrary.int import io.kotest.property.checkAll import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import kotlin.time.milliseconds class CancellableF : ArrowFxSpec(spec = { @@ -104,7 +105,7 @@ class CancellableF : ArrowFxSpec(spec = { ForkConnected { cancel.invoke() } // Let cancel schedule - delay(10.milliseconds.millis) + delay(10.milliseconds) start.complete(Unit) // Continue cancellableF diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ConcurrentVarTest.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ConcurrentVarTest.kt index 6fe8cbfd4..e040596b8 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ConcurrentVarTest.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ConcurrentVarTest.kt @@ -5,9 +5,8 @@ import arrow.core.toT import io.kotest.assertions.fail import io.kotest.matchers.shouldBe import kotlinx.coroutines.delay -import kotlin.time.ExperimentalTime +import kotlin.time.milliseconds -@ExperimentalTime class ConcurrentVarTest : ArrowFxSpec(spec = { "empty; put; isNotEmpty; take; put; take" { @@ -193,7 +192,7 @@ class ConcurrentVarTest : ArrowFxSpec(spec = { ForkAndForget { mVar.put(1) } val p2 = ForkAndForget { mVar.put(2) } ForkAndForget { mVar.put(3) } - delay(10.milliseconds.millis) // Give put callbacks a chance to register + delay(10.milliseconds) // Give put callbacks a chance to register p2.cancel() mVar.take() val r1 = mVar.take() @@ -206,7 +205,7 @@ class ConcurrentVarTest : ArrowFxSpec(spec = { val t1 = ForkAndForget { mVar.take() } val t2 = ForkAndForget { mVar.take() } val t3 = ForkAndForget { mVar.take() } - delay(10.milliseconds.millis) // Give take callbacks a chance to register + delay(10.milliseconds) // Give take callbacks a chance to register t2.cancel() mVar.put(1) mVar.put(3) @@ -222,10 +221,10 @@ class ConcurrentVarTest : ArrowFxSpec(spec = { mVar.read() finished.complete(1) } - delay(100.milliseconds.millis) // Give read callback a chance to register + delay(100.milliseconds) // Give read callback a chance to register fiber.cancel() mVar.put(10) - val fallback = suspend { delay(200.milliseconds.millis); 0 } + val fallback = suspend { delay(200.milliseconds); 0 } raceN(finished::get, fallback) shouldBe Either.Right(0) } @@ -252,7 +251,7 @@ class ConcurrentVarTest : ArrowFxSpec(spec = { finished.complete(Unit) } } - delay(100.milliseconds.millis) + delay(100.milliseconds) fiber.cancel() started.tryGet() shouldBe 10 finished.tryGet() shouldBe null @@ -283,7 +282,7 @@ class ConcurrentVarTest : ArrowFxSpec(spec = { it + 1 } } - delay(10.milliseconds.millis) + delay(10.milliseconds) fiber.cancel() started.get() shouldBe 10 finished.tryGet() shouldBe null diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/EnvironmentTest.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/EnvironmentTest.kt index 063b19597..f35270c89 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/EnvironmentTest.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/EnvironmentTest.kt @@ -7,6 +7,7 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.checkAll import kotlinx.coroutines.delay +import kotlin.time.milliseconds class EnvironmentTest : StringSpec({ @@ -74,7 +75,7 @@ class EnvironmentTest : StringSpec({ } tailrec suspend fun sleeper(): Unit { - delay(1.milliseconds.millis) + delay(1.milliseconds) sleeper() } diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ParTraverseTest.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ParTraverseTest.kt index adfa744d8..1401749bd 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ParTraverseTest.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ParTraverseTest.kt @@ -8,6 +8,8 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list import io.kotest.property.checkAll +import kotlinx.coroutines.withTimeoutOrNull +import kotlin.time.milliseconds class ParTraverseTest : ArrowFxSpec(spec = { @@ -129,7 +131,7 @@ class ParTraverseTest : ArrowFxSpec(spec = { val promiseB = Promise() val promiseC = Promise() - timeOutOrNull(10.milliseconds) { + withTimeoutOrNull(10.milliseconds) { listOf( suspend { promiseA.get() diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ScheduleTest.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ScheduleTest.kt index 355078f0d..233086a39 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ScheduleTest.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ScheduleTest.kt @@ -5,7 +5,9 @@ import arrow.core.Eval import io.kotest.assertions.fail import io.kotest.matchers.should import io.kotest.matchers.shouldBe +import kotlinx.coroutines.withTimeoutOrNull import kotlin.math.pow +import kotlin.time.milliseconds class ScheduleTest : ArrowFxSpec(spec = { @@ -101,7 +103,7 @@ class ScheduleTest : ArrowFxSpec(spec = { } "Schedule.never() times out" { - timeOutOrNull(10.milliseconds) { + withTimeoutOrNull(10.milliseconds) { val a: Nothing = repeat(Schedule.never()) { 1 } diff --git a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/SemaphoreTest.kt b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/SemaphoreTest.kt index 2ac91c19e..44b40c15e 100644 --- a/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/SemaphoreTest.kt +++ b/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/SemaphoreTest.kt @@ -9,6 +9,8 @@ import io.kotest.property.arbitrary.map import io.kotest.property.arbitrary.positiveInts import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.withTimeoutOrNull +import kotlin.time.milliseconds class SemaphoreTest : ArrowFxSpec(spec = { @@ -186,7 +188,7 @@ class SemaphoreTest : ArrowFxSpec(spec = { checkAll(Arb.positiveInts().map(Int::toLong)) { n -> // 100 iterations takes 1 second val s = Semaphore(n) - val r = timeOutOrNull(10.milliseconds) { + val r = withTimeoutOrNull(10.milliseconds) { s.withPermitN(n + 1) { // Requests a n + 1 permits, puts count to -1 s.release() // Timeouts out due to no permit } // cancel should put count back to 0 @@ -218,7 +220,7 @@ class SemaphoreTest : ArrowFxSpec(spec = { checkAll(Arb.positiveInts().map(Int::toLong)) { n -> // 100 iterations takes 1 second val s = Semaphore(n) - val x = timeOutOrNull(10.milliseconds) { + val x = withTimeoutOrNull(10.milliseconds) { // Puts count to -1, and times out before acquired so should out count back to 1 s.acquireN(n + 1) s.release() // Never runs diff --git a/arrow-fx-stm/build.gradle b/arrow-fx-stm/build.gradle index 23702daae..495d9f9b8 100644 --- a/arrow-fx-stm/build.gradle +++ b/arrow-fx-stm/build.gradle @@ -1,5 +1,13 @@ +plugins { + id "org.jetbrains.kotlin.jvm" + id "org.jlleitschuh.gradle.ktlint" +} + apply plugin: 'kotlinx-atomicfu' +apply from: "$SUB_PROJECT" +apply from: "$DOC_CREATION" + dependencies { api "io.arrow-kt:arrow-core:$VERSION_NAME" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLINX_COROUTINES_VERSION" @@ -9,3 +17,15 @@ dependencies { testImplementation "io.kotest:kotest-assertions-core-jvm:$KOTEST_VERSION" // for kotest core jvm assertions testImplementation "io.kotest:kotest-property-jvm:$KOTEST_VERSION" // for kotest property test } + +// usage of kotlin.time +compileKotlin { + kotlinOptions { + freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"] + } +} +compileTestKotlin { + kotlinOptions { + freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"] + } +} \ No newline at end of file diff --git a/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/STMTest.kt b/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/STMTest.kt index 7fbe75142..6aa2db88d 100644 --- a/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/STMTest.kt +++ b/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/STMTest.kt @@ -3,11 +3,10 @@ package arrow.fx.stm import arrow.fx.coroutines.ArrowFxSpec import arrow.fx.coroutines.Fiber import arrow.fx.coroutines.ForkConnected -import arrow.fx.coroutines.microseconds -import arrow.fx.coroutines.milliseconds +import kotlin.time.microseconds +import kotlin.time.milliseconds import arrow.fx.coroutines.parMapN import arrow.fx.coroutines.parTraverse -import arrow.fx.coroutines.timeOutOrNull import arrow.fx.stm.internal.BlockedIndefinitely import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.ints.shouldBeExactly @@ -17,6 +16,7 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.bool import io.kotest.property.arbitrary.int import kotlinx.coroutines.delay +import kotlinx.coroutines.withTimeoutOrNull class STMTest : ArrowFxSpec(spec = { "no-effects" { @@ -74,7 +74,7 @@ class STMTest : ArrowFxSpec(spec = { shouldThrow { atomically { retry() } } } "retry should suspend forever if no read variable changes" { - timeOutOrNull(500.milliseconds) { + withTimeoutOrNull(500.milliseconds) { val tv = TVar.new(0) atomically { if (tv.read() == 0) retry() @@ -85,7 +85,7 @@ class STMTest : ArrowFxSpec(spec = { "a suspended transaction will resume if a variable changes" { val tv = TVar.new(0) val f = ForkConnected { - delay(500.milliseconds.millis) + delay(500.milliseconds) atomically { tv.modify { it + 1 } } } atomically { @@ -101,11 +101,11 @@ class STMTest : ArrowFxSpec(spec = { val v2 = TVar.new(0) val v3 = TVar.new(0) val f = ForkConnected { - delay(500.milliseconds.millis) + delay(500.milliseconds) atomically { v1.modify { it + 1 } } - delay(500.milliseconds.millis) + delay(500.milliseconds) atomically { v2.modify { it + 1 } } - delay(500.milliseconds.millis) + delay(500.milliseconds) atomically { v3.modify { it + 1 } } } atomically { @@ -150,7 +150,7 @@ class STMTest : ArrowFxSpec(spec = { checkAll { val tv = TVar.new(0) val f = ForkConnected { - delay(10.microseconds.millis) + delay(10.microseconds) atomically { tv.modify { it + 1 } } } atomically { @@ -221,7 +221,7 @@ class STMTest : ArrowFxSpec(spec = { } }, { atomically { acc1.modify { it - 60 } } - delay(20.milliseconds.millis) + delay(20.milliseconds) atomically { acc1.modify { it + 60 } } }, { _, _ -> Unit }) acc1.unsafeRead() shouldBeExactly 50 diff --git a/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/TVarTest.kt b/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/TVarTest.kt index 7e7fbad9d..54a09612a 100644 --- a/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/TVarTest.kt +++ b/arrow-fx-stm/src/test/kotlin/arrow/fx/stm/TVarTest.kt @@ -1,7 +1,7 @@ package arrow.fx.stm import arrow.fx.coroutines.ArrowFxSpec -import arrow.fx.coroutines.milliseconds +import kotlin.time.milliseconds import arrow.fx.coroutines.raceN import arrow.fx.stm.internal.STMFrame import io.kotest.matchers.ints.shouldBeExactly @@ -27,14 +27,14 @@ class TVarTest : ArrowFxSpec(spec = { val sleepWon = CompletableDeferred() val job1 = launch { - raceN(Dispatchers.IO, { delay(50.milliseconds.millis); sleepWon.complete(Unit) }, { tv.unsafeRead() }) + raceN(Dispatchers.IO, { delay(50.milliseconds); sleepWon.complete(Unit) }, { tv.unsafeRead() }) .fold({}, { throw IllegalStateException("Lock did not lock!") }) } sleepWon.await() val sleepWon2 = CompletableDeferred() val job2 = launch { - raceN(Dispatchers.IO, { delay(50.milliseconds.millis); sleepWon2.complete(Unit) }, { tv.lock(STMFrame()) }) + raceN(Dispatchers.IO, { delay(50.milliseconds); sleepWon2.complete(Unit) }, { tv.lock(STMFrame()) }) .fold({}, { throw IllegalStateException("Lock did not lock!") }) } sleepWon2.await() @@ -52,7 +52,7 @@ class TVarTest : ArrowFxSpec(spec = { val sleepWon = CompletableDeferred() val job1 = launch { - raceN(Dispatchers.IO, { delay(50.milliseconds.millis); sleepWon.complete(Unit) }, { tv.unsafeRead() }) + raceN(Dispatchers.IO, { delay(50.milliseconds); sleepWon.complete(Unit) }, { tv.unsafeRead() }) .fold({}, { throw IllegalStateException("Lock did not lock!") }) } sleepWon.await() @@ -62,7 +62,7 @@ class TVarTest : ArrowFxSpec(spec = { val sleepWon2 = CompletableDeferred() val job2 = launch { - raceN(Dispatchers.IO, { delay(50.milliseconds.millis); sleepWon2.complete(Unit) }, { tv.unsafeRead() }) + raceN(Dispatchers.IO, { delay(50.milliseconds); sleepWon2.complete(Unit) }, { tv.unsafeRead() }) .fold({}, { throw IllegalStateException("Lock did not lock!") }) } sleepWon2.await() diff --git a/arrow-fx/src/test/kotlin/arrow/fx/IOTest.kt b/arrow-fx/src/test/kotlin/arrow/fx/IOTest.kt index 9aec50a9f..6433c7cd3 100644 --- a/arrow-fx/src/test/kotlin/arrow/fx/IOTest.kt +++ b/arrow-fx/src/test/kotlin/arrow/fx/IOTest.kt @@ -38,6 +38,7 @@ import io.kotlintest.matchers.types.shouldBeInstanceOf import io.kotlintest.properties.Gen import io.kotlintest.shouldBe import kotlinx.coroutines.CoroutineName +import kotlinx.coroutines.delay import kotlinx.coroutines.newSingleThreadContext import kotlinx.coroutines.withTimeoutOrNull import kotlin.coroutines.AbstractCoroutineContextElement From f9fa4cf262cdcf86fd3d6338115152ec62d79c49 Mon Sep 17 00:00:00 2001 From: i-walker <46971368+i-walker@users.noreply.github.com> Date: Wed, 23 Dec 2020 12:52:02 +0100 Subject: [PATCH 3/3] resolve CI error building the project and further replacements --- arrow-fx-kotlinx-coroutines/build.gradle | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arrow-fx-kotlinx-coroutines/build.gradle b/arrow-fx-kotlinx-coroutines/build.gradle index 9f04bbf60..ee5864478 100644 --- a/arrow-fx-kotlinx-coroutines/build.gradle +++ b/arrow-fx-kotlinx-coroutines/build.gradle @@ -15,3 +15,15 @@ dependencies { testImplementation project(':arrow-fx') testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$KOTLINX_COROUTINES_VERSION" } + +// usage of kotlin.time +compileKotlin { + kotlinOptions { + freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"] + } +} +compileTestKotlin { + kotlinOptions { + freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"] + } +} \ No newline at end of file