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

Support JS for Arrow Fx #2444

Merged
merged 19 commits into from
Jul 8, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arrow-libs/core/arrow-annotations/karma.config.d
4 changes: 2 additions & 2 deletions arrow-libs/core/arrow-continuations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ kotlin {
testTask {
useKarma {
useChromeHeadless()
useConfigDirectory("${project.rootDir}/karma")
}
}
}
nodejs {
testTask {
useMocha {
timeout = "10000000000"
timeout = "600000"
}
}
}
Expand Down Expand Up @@ -57,6 +56,7 @@ kotlin {
jsTest {
dependencies {
implementation "io.kotest:kotest-framework-engine:$KOTEST_VERSION"

}
}
}
Expand Down
1 change: 1 addition & 0 deletions arrow-libs/core/arrow-continuations/karma.config.d
1 change: 1 addition & 0 deletions arrow-libs/core/arrow-core-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ kotlin {
jsTest {
dependencies {
implementation "io.kotest:kotest-framework-engine:$KOTEST_VERSION"

}
}
}
Expand Down
1 change: 1 addition & 0 deletions arrow-libs/core/arrow-core-test/karma.config.d
4 changes: 2 additions & 2 deletions arrow-libs/core/arrow-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ kotlin {
testTask {
useKarma {
useChromeHeadless()
useConfigDirectory("${project.rootDir}/karma")
}
}
}
nodejs {
testTask {
useMocha {
timeout = "10000000000"
timeout = "600000"
}
}
}
Expand Down Expand Up @@ -60,6 +59,7 @@ kotlin {
jsTest {
dependencies {
implementation "io.kotest:kotest-framework-engine:$KOTEST_VERSION"

}
}
}
Expand Down
1 change: 1 addition & 0 deletions arrow-libs/core/arrow-core/karma.config.d
15 changes: 15 additions & 0 deletions arrow-libs/fx/arrow-fx-coroutines-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ apply from: "$PUBLICATION_MPP"
apply from: "$ANIMALSNIFFER_MPP"

kotlin {
js(BOTH) {
browser()
nodejs()
}
sourceSets {
commonMain {
dependencies {
Expand All @@ -34,5 +38,16 @@ kotlin {
runtimeOnly "io.kotest:kotest-runner-junit5:$KOTEST_VERSION"
}
}
jsMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-js:$KOTLIN_VERSION"
}
}
jsTest {
dependencies {
implementation "io.kotest:kotest-framework-engine:$KOTEST_VERSION"

}
}
}
}
1 change: 1 addition & 0 deletions arrow-libs/fx/arrow-fx-coroutines-test/karma.config.d
27 changes: 27 additions & 0 deletions arrow-libs/fx/arrow-fx-coroutines/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ apply from: "$DOC_CREATION"
apply from: "$PUBLICATION_MPP"

kotlin {
js(BOTH) {
browser {
testTask {
useKarma {
useChromeHeadless()
}
}
}
nodejs {
testTask {
useMocha {
timeout = "600000"
}
}
}
}
sourceSets {
commonMain {
dependencies {
Expand All @@ -36,5 +52,16 @@ kotlin {
implementation "io.kotest:kotest-runner-junit5:$KOTEST_VERSION"
}
}
jsMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-js:$KOTLIN_VERSION"
}
}
jsTest {
dependencies {
implementation "io.kotest:kotest-framework-engine:$KOTEST_VERSION"

}
}
}
}
1 change: 1 addition & 0 deletions arrow-libs/fx/arrow-fx-coroutines/karma.config.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package arrow.fx.coroutines

import arrow.core.Either
import arrow.core.test.stackSafeIteration
import io.kotest.assertions.fail
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.matchers.shouldBe
Expand Down Expand Up @@ -253,15 +254,15 @@ class CircuitBreakerTest : ArrowFxSpec(
"should be stack safe for successful async tasks" {
stackSafeSuspend(
CircuitBreaker.of(maxFailures = 5, resetTimeout = 1.minutes)!!,
20_000, 0
) shouldBe 20_000
stackSafeIteration(), 0
) shouldBe stackSafeIteration()
}

"should be stack safe for successful immediate tasks" {
stackSafeImmediate(
CircuitBreaker.of(maxFailures = 5, resetTimeout = 1.minutes)!!,
20_000, 0
) shouldBe 20_000
stackSafeIteration(), 0
) shouldBe stackSafeIteration()
}
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package arrow.fx.coroutines

import arrow.core.Either
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldStartWith
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.list
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.withTimeoutOrNull
import kotlin.time.ExperimentalTime
Expand Down Expand Up @@ -54,7 +51,7 @@ class ParTraverseTest : ArrowFxSpec(
Arb.throwable()
) { n, killOn, e ->
Either.catch {
(0 until n).parTraverse(Dispatchers.IO) { i ->
(0 until n).parTraverse { i ->
if (i == killOn) throw e else unit()
}
} should leftException(e)
Expand All @@ -73,17 +70,6 @@ class ParTraverseTest : ArrowFxSpec(
l shouldBe (0 until count).toList()
}

"parTraverse runs on provided context " { // 100 is same default length as Arb.list
checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i ->
val res = single.use { ctx ->
(0 until i).parTraverse(ctx) { Thread.currentThread().name }
}
assertSoftly {
res.forEach { it shouldStartWith "single" }
}
}
}

"parTraverseN can traverse effect full computations" {
val ref = Atomic(0)
(0 until 100).parTraverseN(5) {
Expand All @@ -92,19 +78,6 @@ class ParTraverseTest : ArrowFxSpec(
ref.get() shouldBe 100
}

"parTraverseN runs on provided thread" {
checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i ->
val res = single.use { ctx ->
(0 until i).parTraverseN(ctx, 3) {
Thread.currentThread().name
}
}
assertSoftly {
res.forEach { it shouldStartWith "single" }
}
}
}

"parTraverseN(3) runs in (3) parallel" {
val promiseA = CompletableDeferred<Unit>()
val promiseB = CompletableDeferred<Unit>()
Expand Down Expand Up @@ -162,7 +135,7 @@ class ParTraverseTest : ArrowFxSpec(
Arb.throwable()
) { n, killOn, e ->
Either.catch {
(0 until n).parTraverseN(Dispatchers.IO, 3) { i ->
(0 until n).parTraverseN(3) { i ->
if (i == killOn) throw e else unit()
}
} should leftException(e)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package arrow.fx.coroutines

actual fun timeInMillis(): Long {
val x: Number = js("new Date().getTime()")
return x.toLong()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package arrow.fx.coroutines

import io.kotest.assertions.assertSoftly
import io.kotest.matchers.string.shouldStartWith
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int

class ParTraverseJvmTest : ArrowFxSpec(spec = {
"parTraverse runs on provided context " { // 100 is same default length as Arb.list
checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i ->
val res = single.use { ctx ->
(0 until i).parTraverse(ctx) { Thread.currentThread().name }
}
assertSoftly {
res.forEach { it shouldStartWith "single" }
}
}
}

"parTraverseN runs on provided thread" {
checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i ->
val res = single.use { ctx ->
(0 until i).parTraverseN(ctx, 3) {
Thread.currentThread().name
}
}
assertSoftly {
res.forEach { it shouldStartWith "single" }
}
}
}
})
36 changes: 31 additions & 5 deletions arrow-libs/fx/arrow-fx-stm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ apply from: "$PUBLICATION_MPP"
apply from: "$ANIMALSNIFFER_MPP"

kotlin {
js(BOTH) {
browser {
testTask {
useKarma {
useChromeHeadless()
}
}
}
nodejs {
testTask {
useMocha {
timeout = "600000"
}
}
}
}
sourceSets {
commonMain {
dependencies {
Expand All @@ -20,21 +36,31 @@ kotlin {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLINX_COROUTINES_VERSION"
}
}

jvmMain {
commonTest {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
implementation project(":arrow-fx-coroutines-test")
}
}
commonTest {
jvmMain {
dependencies {
implementation project(":arrow-fx-coroutines-test")
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
}
}
jvmTest {
dependencies {
implementation "io.kotest:kotest-runner-junit5:$KOTEST_VERSION"
}
}
jsMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-js:$KOTLIN_VERSION"
}
}
jsTest {
dependencies {
implementation "io.kotest:kotest-framework-engine:$KOTEST_VERSION"

}
}
}
}
1 change: 1 addition & 0 deletions arrow-libs/fx/arrow-fx-stm/karma.config.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package arrow.fx.stm

import arrow.core.Predicate
import kotlin.js.JsName

fun <A> STM.newTQueue(): TQueue<A> = TQueue(newTVar(PList.Nil), newTVar(PList.Nil))

Expand Down Expand Up @@ -249,7 +250,7 @@ data class TQueue<A> internal constructor(
* implement queues.
*/
internal sealed class PList<out A> {
data class Cons<A>(val value: A, val tail: PList<A>) : PList<A>()
data class Cons<A>(val value: A, @JsName("_tail") val tail: PList<A>) : PList<A>()
object Nil : PList<Nothing>()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,19 @@ class STMTest : ArrowFxSpec(
acc2.unsafeRead() shouldBeExactly 250
}
}
"concurrent example 2" {

// TypeError: Cannot read property 'toString' of undefined
// at ObjectLiteral_0.test(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:3661)
// at <global>.invokeMatcher(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:19216)
// at <global>.should(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:19212)
// at <global>.shouldBeInRange(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:3652)
// at STMTransaction.f(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:261217)
// at commit.doResume(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:270552)
// at commit.CoroutineImpl.resumeWith(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:118697)
// at CancellableContinuationImpl.DispatchedTask.run(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:174593)
// at WindowMessageQueue.MessageQueue.process(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:177985)
// at <global>.<unknown>(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:177940)
"concurrent example 2".config(enabled = false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something we can report to karma or somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to make a ticket for this in Kotlin. It's failing on generated code.

checkAll {
val tq = TQueue.new<Int>()
parZip(
Expand Down
Loading