From 9149cbe52b2089b304fff268ca3c2844f16507df Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Thu, 5 Dec 2024 21:38:01 +0200 Subject: [PATCH 01/17] Update ktor --- gradle/libs.versions.toml | 2 +- .../io/rsocket/kotlin/transport/ktor/tcp/KtorTcpConnection.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6dbaa5d6..32d551fc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,7 +7,7 @@ kotlinx-coroutines = "1.9.0" kotlinx-benchmark = "0.4.8" kotlinx-bcv = "0.16.3" -ktor = "3.0.1" +ktor = "3.0.2" netty = "4.1.115.Final" netty-quic = "0.0.69.Final" diff --git a/rsocket-transports/ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/KtorTcpConnection.kt b/rsocket-transports/ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/KtorTcpConnection.kt index 3ad8ac7d..a07d44e3 100644 --- a/rsocket-transports/ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/KtorTcpConnection.kt +++ b/rsocket-transports/ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/KtorTcpConnection.kt @@ -91,13 +91,13 @@ private class KtorTcpConnection( } } -@OptIn(InternalAPI::class) // TODO? +@OptIn(InternalAPI::class) private fun ByteWriteChannel.writeFrame(frame: Buffer) { writeBuffer.writeInt24(frame.size.toInt()) writeBuffer.transferFrom(frame) } -@OptIn(InternalAPI::class) // TODO? +@OptIn(InternalAPI::class) private suspend fun ByteReadChannel.readFrame(): Buffer? { while (availableForRead < 3 && awaitContent(3)) yield() if (availableForRead == 0) return null From 7a04217c34aaf2a1d80e08af91eeada30fd184bf Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Tue, 12 Nov 2024 00:09:30 +0200 Subject: [PATCH 02/17] Support more K/N targets --- .../src/main/kotlin/rsocketbuild/targets.kt | 20 ++++++++----------- .../ktor-server-rsocket/build.gradle.kts | 2 +- .../rsocket-ktor-server/build.gradle.kts | 2 +- rsocket-transports/ktor-tcp/build.gradle.kts | 2 +- .../ktor-websocket-server/build.gradle.kts | 2 +- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/build-logic/src/main/kotlin/rsocketbuild/targets.kt b/build-logic/src/main/kotlin/rsocketbuild/targets.kt index 3ef9d40e..7750833e 100644 --- a/build-logic/src/main/kotlin/rsocketbuild/targets.kt +++ b/build-logic/src/main/kotlin/rsocketbuild/targets.kt @@ -32,29 +32,25 @@ fun KotlinMultiplatformExtension.appleTargets() { watchosArm32() watchosArm64() watchosSimulatorArm64() - // https://youtrack.jetbrains.com/issue/KTOR-6368, supported by kotlinx-io - // watchosDeviceArm64() + watchosDeviceArm64() tvosX64() tvosArm64() tvosSimulatorArm64() } -fun KotlinMultiplatformExtension.nixTargets() { +fun KotlinMultiplatformExtension.nativeTargets() { appleTargets() + linuxX64() linuxArm64() -} - -fun KotlinMultiplatformExtension.nativeTargets() { - nixTargets() mingwX64() - // not supported by ktor, supported by kotlinx-io - // androidNativeX64() - // androidNativeX86() - // androidNativeArm64() - // androidNativeArm32() +// TODO: there are some issues with androidNative targets with Kotlin 2.1.0 +// androidNativeX64() +// androidNativeX86() +// androidNativeArm64() +// androidNativeArm32() } fun KotlinMultiplatformExtension.jsTarget( diff --git a/ktor-plugins/ktor-server-rsocket/build.gradle.kts b/ktor-plugins/ktor-server-rsocket/build.gradle.kts index 7ebb510e..a7681fc5 100644 --- a/ktor-plugins/ktor-server-rsocket/build.gradle.kts +++ b/ktor-plugins/ktor-server-rsocket/build.gradle.kts @@ -24,7 +24,7 @@ description = "rsocket-kotlin ktor server plugin" kotlin { jvmTarget() - nixTargets() + nativeTargets() sourceSets { commonMain.dependencies { diff --git a/ktor-plugins/rsocket-ktor-server/build.gradle.kts b/ktor-plugins/rsocket-ktor-server/build.gradle.kts index a7aeeba4..163b803f 100644 --- a/ktor-plugins/rsocket-ktor-server/build.gradle.kts +++ b/ktor-plugins/rsocket-ktor-server/build.gradle.kts @@ -24,7 +24,7 @@ description = "OLD ARTIFACT - migrate to ktor-server-rsocket" kotlin { jvmTarget() - nixTargets() + nativeTargets() sourceSets { commonMain.dependencies { diff --git a/rsocket-transports/ktor-tcp/build.gradle.kts b/rsocket-transports/ktor-tcp/build.gradle.kts index 7c4cf76d..d6fe6549 100644 --- a/rsocket-transports/ktor-tcp/build.gradle.kts +++ b/rsocket-transports/ktor-tcp/build.gradle.kts @@ -24,7 +24,7 @@ description = "rsocket-kotlin ktor TCP client/server transport implementation" kotlin { jvmTarget() - nixTargets() + nativeTargets() sourceSets { commonMain.dependencies { diff --git a/rsocket-transports/ktor-websocket-server/build.gradle.kts b/rsocket-transports/ktor-websocket-server/build.gradle.kts index ae436493..0f7ad5b1 100644 --- a/rsocket-transports/ktor-websocket-server/build.gradle.kts +++ b/rsocket-transports/ktor-websocket-server/build.gradle.kts @@ -24,7 +24,7 @@ description = "rsocket-kotlin ktor WebSocket server transport implementation" kotlin { jvmTarget() - nixTargets() + nativeTargets() sourceSets { commonMain.dependencies { From ca9c1b0a93c474245ab4f9eab68551d5957cc507 Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Tue, 12 Nov 2024 00:21:55 +0200 Subject: [PATCH 03/17] Support wasm targets for core, tests and local transport --- ...rsocketbuild.multiplatform-base.gradle.kts | 11 ++++ .../src/main/kotlin/rsocketbuild/targets.kt | 27 +++++++++ rsocket-core/build.gradle.kts | 4 +- .../kotlin/logging/DefaultLoggerFactory.kt | 57 ------------------- .../kotlin/logging/DefaultLoggerFactory.kt | 4 +- rsocket-internal-io/build.gradle.kts | 4 +- rsocket-test/build.gradle.kts | 4 +- .../kotlin/io/rsocket/kotlin/test/Test.kt | 27 +++++++++ .../kotlin/io/rsocket/kotlin/test/Test.kt | 27 +++++++++ rsocket-transport-tests/build.gradle.kts | 4 +- rsocket-transports/local/build.gradle.kts | 4 +- 11 files changed, 99 insertions(+), 74 deletions(-) delete mode 100644 rsocket-core/src/jsMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt rename rsocket-core/src/{nativeMain => nonJvmMain}/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt (85%) create mode 100644 rsocket-test/src/wasmJsMain/kotlin/io/rsocket/kotlin/test/Test.kt create mode 100644 rsocket-test/src/wasmWasiMain/kotlin/io/rsocket/kotlin/test/Test.kt diff --git a/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts b/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts index b5eb9b7e..70140f29 100644 --- a/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts +++ b/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts @@ -41,6 +41,17 @@ kotlin { optIn.addAll(OptIns.ExperimentalSubclassOptIn) } + applyDefaultHierarchyTemplate { + common { + group("nonJvm") { + withJs() + withWasmJs() + withWasmWasi() + group("native") + } + } + } + sourceSets.configureEach { languageSettings { if (name.contains("test", ignoreCase = true)) { diff --git a/build-logic/src/main/kotlin/rsocketbuild/targets.kt b/build-logic/src/main/kotlin/rsocketbuild/targets.kt index 7750833e..ac5c8ae7 100644 --- a/build-logic/src/main/kotlin/rsocketbuild/targets.kt +++ b/build-logic/src/main/kotlin/rsocketbuild/targets.kt @@ -18,8 +18,17 @@ package rsocketbuild import org.gradle.jvm.toolchain.* import org.gradle.kotlin.dsl.* +import org.jetbrains.kotlin.gradle.* import org.jetbrains.kotlin.gradle.dsl.* +fun KotlinMultiplatformExtension.allTargets() { + jvmTarget() + jsTarget() + wasmJsTarget() + wasmWasiTarget() + nativeTargets() +} + fun KotlinMultiplatformExtension.appleTargets() { macosX64() macosArm64() @@ -63,6 +72,24 @@ fun KotlinMultiplatformExtension.jsTarget( } } +@OptIn(ExperimentalWasmDsl::class) +fun KotlinMultiplatformExtension.wasmJsTarget( + supportsNode: Boolean = true, + supportsBrowser: Boolean = true, +) { + wasmJs { + if (supportsNode) nodejs() + if (supportsBrowser) browser() + } +} + +@OptIn(ExperimentalWasmDsl::class) +fun KotlinMultiplatformExtension.wasmWasiTarget() { + wasmWasi { + nodejs() + } +} + fun KotlinMultiplatformExtension.jvmTarget( jdkVersion: Int = 8, jdkAdditionalTestVersions: Set = setOf(11, 17, 21), diff --git a/rsocket-core/build.gradle.kts b/rsocket-core/build.gradle.kts index 87aa8634..dbdf05ef 100644 --- a/rsocket-core/build.gradle.kts +++ b/rsocket-core/build.gradle.kts @@ -24,9 +24,7 @@ plugins { description = "rsocket-kotlin core functionality" kotlin { - jvmTarget() - jsTarget() - nativeTargets() + allTargets() sourceSets { commonMain.dependencies { diff --git a/rsocket-core/src/jsMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt b/rsocket-core/src/jsMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt deleted file mode 100644 index dcde87bc..00000000 --- a/rsocket-core/src/jsMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2015-2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.kotlin.logging - -import io.rsocket.kotlin.* - -@RSocketLoggingApi -internal actual val DefaultLoggerFactory: LoggerFactory - get() = ConsoleLogger - -@RSocketLoggingApi -public class ConsoleLogger( - override val tag: String, - private val minLevel: LoggingLevel = LoggingLevel.INFO, -) : Logger { - override fun isLoggable(level: LoggingLevel): Boolean = level >= minLevel - override fun rawLog(level: LoggingLevel, throwable: Throwable?, message: Any?) { - val meta = "[$level] ($tag)" - when (level) { - LoggingLevel.ERROR -> throwable - ?.let { console.error(meta, message, "Error:", it) } - ?: console.error(meta, message) - LoggingLevel.WARN -> throwable - ?.let { console.warn(meta, message, "Error:", it) } - ?: console.warn(meta, message) - LoggingLevel.INFO -> throwable - ?.let { console.info(meta, message, "Error:", it) } - ?: console.info(meta, message) - LoggingLevel.DEBUG -> throwable - ?.let { console.log(meta, message, "Error:", it) } - ?: console.log(meta, message) - LoggingLevel.TRACE -> throwable - ?.let { console.log(meta, message, "Error:", it) } - ?: console.log(meta, message) - } - } - - public companion object : LoggerFactory { - override fun logger(tag: String): Logger = ConsoleLogger(tag) - - public fun withLevel(minLevel: LoggingLevel): LoggerFactory = LoggerFactory { ConsoleLogger(it, minLevel) } - } -} diff --git a/rsocket-core/src/nativeMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt b/rsocket-core/src/nonJvmMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt similarity index 85% rename from rsocket-core/src/nativeMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt rename to rsocket-core/src/nonJvmMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt index d234e402..ce8db463 100644 --- a/rsocket-core/src/nativeMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt +++ b/rsocket-core/src/nonJvmMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,5 +19,5 @@ package io.rsocket.kotlin.logging import io.rsocket.kotlin.* @RSocketLoggingApi -public actual val DefaultLoggerFactory: LoggerFactory +internal actual val DefaultLoggerFactory: LoggerFactory get() = PrintLogger diff --git a/rsocket-internal-io/build.gradle.kts b/rsocket-internal-io/build.gradle.kts index 7211178b..4e1e4892 100644 --- a/rsocket-internal-io/build.gradle.kts +++ b/rsocket-internal-io/build.gradle.kts @@ -23,9 +23,7 @@ plugins { description = "rsocket-kotlin internal IO support" kotlin { - jvmTarget() - jsTarget() - nativeTargets() + allTargets() sourceSets { commonMain.dependencies { diff --git a/rsocket-test/build.gradle.kts b/rsocket-test/build.gradle.kts index f15aebc9..c54fc308 100644 --- a/rsocket-test/build.gradle.kts +++ b/rsocket-test/build.gradle.kts @@ -24,9 +24,7 @@ plugins { @OptIn(ExperimentalKotlinGradlePluginApi::class) kotlin { - jvmTarget() - jsTarget() - nativeTargets() + allTargets() compilerOptions { freeCompilerArgs.add("-Xexpect-actual-classes") diff --git a/rsocket-test/src/wasmJsMain/kotlin/io/rsocket/kotlin/test/Test.kt b/rsocket-test/src/wasmJsMain/kotlin/io/rsocket/kotlin/test/Test.kt new file mode 100644 index 00000000..e31d889c --- /dev/null +++ b/rsocket-test/src/wasmJsMain/kotlin/io/rsocket/kotlin/test/Test.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2015-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.rsocket.kotlin.test + +import kotlinx.coroutines.* + +actual annotation class IgnoreJs +actual annotation class IgnoreJvm +actual annotation class IgnoreNative + +actual val anotherDispatcher: CoroutineDispatcher get() = Dispatchers.Default + +actual fun identityHashCode(instance: Any): Int = instance.hashCode() diff --git a/rsocket-test/src/wasmWasiMain/kotlin/io/rsocket/kotlin/test/Test.kt b/rsocket-test/src/wasmWasiMain/kotlin/io/rsocket/kotlin/test/Test.kt new file mode 100644 index 00000000..e31d889c --- /dev/null +++ b/rsocket-test/src/wasmWasiMain/kotlin/io/rsocket/kotlin/test/Test.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2015-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.rsocket.kotlin.test + +import kotlinx.coroutines.* + +actual annotation class IgnoreJs +actual annotation class IgnoreJvm +actual annotation class IgnoreNative + +actual val anotherDispatcher: CoroutineDispatcher get() = Dispatchers.Default + +actual fun identityHashCode(instance: Any): Int = instance.hashCode() diff --git a/rsocket-transport-tests/build.gradle.kts b/rsocket-transport-tests/build.gradle.kts index a2353b56..142b8954 100644 --- a/rsocket-transport-tests/build.gradle.kts +++ b/rsocket-transport-tests/build.gradle.kts @@ -24,9 +24,7 @@ plugins { @OptIn(ExperimentalKotlinGradlePluginApi::class) kotlin { - jvmTarget() - jsTarget() - nativeTargets() + allTargets() compilerOptions { optIn.addAll( diff --git a/rsocket-transports/local/build.gradle.kts b/rsocket-transports/local/build.gradle.kts index f1755711..7f52357a 100644 --- a/rsocket-transports/local/build.gradle.kts +++ b/rsocket-transports/local/build.gradle.kts @@ -24,9 +24,7 @@ plugins { description = "rsocket-kotlin Local transport implementation" kotlin { - jvmTarget() - jsTarget() - nativeTargets() + allTargets() sourceSets { commonMain.dependencies { From 486fb9d2df13573c687c69fa9834b2fb62273235 Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Tue, 12 Nov 2024 00:29:11 +0200 Subject: [PATCH 04/17] Support wasm-js target in ktor-client modules --- .../main/kotlin/rsocketbuild.multiplatform-base.gradle.kts | 5 +---- ktor-plugins/ktor-client-rsocket/build.gradle.kts | 1 + ktor-plugins/rsocket-ktor-client/build.gradle.kts | 1 + rsocket-transports/ktor-websocket-client/build.gradle.kts | 1 + rsocket-transports/ktor-websocket-internal/build.gradle.kts | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts b/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts index 70140f29..5bf4bd64 100644 --- a/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts +++ b/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts @@ -32,10 +32,7 @@ plugins { @OptIn(ExperimentalKotlinGradlePluginApi::class) kotlin { compilerOptions { - // because of INVISIBLE_REFERENCE suppression - will be removed after migration to kotlinx.io - if (project.name != "rsocket-test") { - allWarningsAsErrors.set(true) - } + allWarningsAsErrors.set(true) progressiveMode.set(true) freeCompilerArgs.add("-Xrender-internal-diagnostic-names") optIn.addAll(OptIns.ExperimentalSubclassOptIn) diff --git a/ktor-plugins/ktor-client-rsocket/build.gradle.kts b/ktor-plugins/ktor-client-rsocket/build.gradle.kts index 9d9b43f8..2122bd12 100644 --- a/ktor-plugins/ktor-client-rsocket/build.gradle.kts +++ b/ktor-plugins/ktor-client-rsocket/build.gradle.kts @@ -25,6 +25,7 @@ description = "rsocket-kotlin ktor client plugin" kotlin { jvmTarget() jsTarget() + wasmJsTarget() nativeTargets() sourceSets { diff --git a/ktor-plugins/rsocket-ktor-client/build.gradle.kts b/ktor-plugins/rsocket-ktor-client/build.gradle.kts index 3312f542..5bbe92fe 100644 --- a/ktor-plugins/rsocket-ktor-client/build.gradle.kts +++ b/ktor-plugins/rsocket-ktor-client/build.gradle.kts @@ -25,6 +25,7 @@ description = "OLD ARTIFACT - migrate to ktor-client-rsocket" kotlin { jvmTarget() jsTarget() + wasmJsTarget() nativeTargets() sourceSets { diff --git a/rsocket-transports/ktor-websocket-client/build.gradle.kts b/rsocket-transports/ktor-websocket-client/build.gradle.kts index f9bcbf6a..7aae725b 100644 --- a/rsocket-transports/ktor-websocket-client/build.gradle.kts +++ b/rsocket-transports/ktor-websocket-client/build.gradle.kts @@ -25,6 +25,7 @@ description = "rsocket-kotlin ktor WebSocket client transport implementation" kotlin { jvmTarget() jsTarget() + wasmJsTarget() nativeTargets() sourceSets { diff --git a/rsocket-transports/ktor-websocket-internal/build.gradle.kts b/rsocket-transports/ktor-websocket-internal/build.gradle.kts index c3583f62..42aeb76d 100644 --- a/rsocket-transports/ktor-websocket-internal/build.gradle.kts +++ b/rsocket-transports/ktor-websocket-internal/build.gradle.kts @@ -25,6 +25,7 @@ description = "rsocket-kotlin ktor WebSocket transport utilities" kotlin { jvmTarget() jsTarget() + wasmJsTarget() nativeTargets() sourceSets { From b7f3d2e2277d6943c7275093539860e2a58503fb Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Sun, 1 Dec 2024 15:29:13 +0200 Subject: [PATCH 05/17] use "127.0.0.1" instead of "0.0.0.0" in ktor tcp server tests because of mingw/windows behaviour --- .../io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt | 2 +- .../io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt b/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt index 732768b7..005f7811 100644 --- a/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt +++ b/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt @@ -25,7 +25,7 @@ import kotlin.test.* class TcpServerTest : SuspendTest { private val testJob = Job() private val testContext = testJob + TestExceptionHandler - private val serverTransport = KtorTcpServerTransport(testContext).target() + private val serverTransport = KtorTcpServerTransport(testContext).target("127.0.0.1") private fun KtorTcpServerInstance.clientTransport() = KtorTcpClientTransport(testContext).target(localAddress) diff --git a/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt b/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt index 72682ce3..1b2e9e1a 100644 --- a/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt +++ b/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt @@ -24,7 +24,7 @@ import kotlinx.coroutines.* @Suppress("DEPRECATION_ERROR") class TcpTransportTest : TransportTest() { override suspend fun before() { - val serverSocket = startServer(TcpServerTransport()).serverSocket.await() + val serverSocket = startServer(TcpServerTransport("127.0.0.1")).serverSocket.await() client = connectClient(TcpClientTransport(serverSocket.localAddress as InetSocketAddress, testContext)) } } @@ -36,7 +36,7 @@ class KtorTcpTransportTest : TransportTest() { override suspend fun before() { val server = startServer(KtorTcpServerTransport(testContext) { selectorManager(selector, false) - }.target()) + }.target("127.0.0.1")) client = connectClient(KtorTcpClientTransport(testContext) { selectorManager(selector, false) }.target(server.localAddress)) From 0b6ea274d666f643d66932a44b04324dd574bcba Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Sun, 1 Dec 2024 16:03:48 +0200 Subject: [PATCH 06/17] run wasm tests --- .github/workflows/run-tests.yml | 2 +- .../main/kotlin/rsocketbuild.multiplatform-base.gradle.kts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0030a4bb..c77f2cdf 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -33,7 +33,7 @@ jobs: fail-fast: false matrix: os: [ 'ubuntu-latest' ] - target: [ 'jvm', 'jvm11', 'jvm17', 'jvm21', 'js', 'native' ] + target: [ 'jvmAll', 'jsAndWasm', 'native' ] include: - os: 'macos-latest' target: 'macos' diff --git a/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts b/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts index 5bf4bd64..fe25fefe 100644 --- a/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts +++ b/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.gradle.* import org.jetbrains.kotlin.gradle.plugin.* import org.jetbrains.kotlin.gradle.plugin.mpp.* import org.jetbrains.kotlin.gradle.targets.js.ir.* +import org.jetbrains.kotlin.gradle.targets.js.testing.* import org.jetbrains.kotlin.gradle.targets.jvm.* import org.jetbrains.kotlin.gradle.targets.jvm.tasks.* import org.jetbrains.kotlin.gradle.targets.native.tasks.* @@ -111,6 +112,12 @@ registerTestAggregationTask( targetFilter = { it.platformType == KotlinPlatformType.jvm } ) +registerTestAggregationTask( + name = "jsAndWasmTest", + taskDependencies = { tasks.withType() }, + targetFilter = { it.platformType == KotlinPlatformType.js || it.platformType == KotlinPlatformType.wasm } +) + registerTestAggregationTask( name = "nativeTest", taskDependencies = { tasks.withType().matching { it.enabled } }, From 10bd90bd0f49202c3c62b992fa75d6c0aca7b5ec Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Tue, 12 Nov 2024 00:09:30 +0200 Subject: [PATCH 07/17] Support more K/N targets --- .../src/main/kotlin/rsocketbuild/targets.kt | 20 ++++++++----------- .../ktor-server-rsocket/build.gradle.kts | 2 +- .../rsocket-ktor-server/build.gradle.kts | 2 +- rsocket-transports/ktor-tcp/build.gradle.kts | 2 +- .../ktor-websocket-server/build.gradle.kts | 2 +- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/build-logic/src/main/kotlin/rsocketbuild/targets.kt b/build-logic/src/main/kotlin/rsocketbuild/targets.kt index 3ef9d40e..7750833e 100644 --- a/build-logic/src/main/kotlin/rsocketbuild/targets.kt +++ b/build-logic/src/main/kotlin/rsocketbuild/targets.kt @@ -32,29 +32,25 @@ fun KotlinMultiplatformExtension.appleTargets() { watchosArm32() watchosArm64() watchosSimulatorArm64() - // https://youtrack.jetbrains.com/issue/KTOR-6368, supported by kotlinx-io - // watchosDeviceArm64() + watchosDeviceArm64() tvosX64() tvosArm64() tvosSimulatorArm64() } -fun KotlinMultiplatformExtension.nixTargets() { +fun KotlinMultiplatformExtension.nativeTargets() { appleTargets() + linuxX64() linuxArm64() -} - -fun KotlinMultiplatformExtension.nativeTargets() { - nixTargets() mingwX64() - // not supported by ktor, supported by kotlinx-io - // androidNativeX64() - // androidNativeX86() - // androidNativeArm64() - // androidNativeArm32() +// TODO: there are some issues with androidNative targets with Kotlin 2.1.0 +// androidNativeX64() +// androidNativeX86() +// androidNativeArm64() +// androidNativeArm32() } fun KotlinMultiplatformExtension.jsTarget( diff --git a/ktor-plugins/ktor-server-rsocket/build.gradle.kts b/ktor-plugins/ktor-server-rsocket/build.gradle.kts index 7ebb510e..a7681fc5 100644 --- a/ktor-plugins/ktor-server-rsocket/build.gradle.kts +++ b/ktor-plugins/ktor-server-rsocket/build.gradle.kts @@ -24,7 +24,7 @@ description = "rsocket-kotlin ktor server plugin" kotlin { jvmTarget() - nixTargets() + nativeTargets() sourceSets { commonMain.dependencies { diff --git a/ktor-plugins/rsocket-ktor-server/build.gradle.kts b/ktor-plugins/rsocket-ktor-server/build.gradle.kts index a7aeeba4..163b803f 100644 --- a/ktor-plugins/rsocket-ktor-server/build.gradle.kts +++ b/ktor-plugins/rsocket-ktor-server/build.gradle.kts @@ -24,7 +24,7 @@ description = "OLD ARTIFACT - migrate to ktor-server-rsocket" kotlin { jvmTarget() - nixTargets() + nativeTargets() sourceSets { commonMain.dependencies { diff --git a/rsocket-transports/ktor-tcp/build.gradle.kts b/rsocket-transports/ktor-tcp/build.gradle.kts index 7c4cf76d..d6fe6549 100644 --- a/rsocket-transports/ktor-tcp/build.gradle.kts +++ b/rsocket-transports/ktor-tcp/build.gradle.kts @@ -24,7 +24,7 @@ description = "rsocket-kotlin ktor TCP client/server transport implementation" kotlin { jvmTarget() - nixTargets() + nativeTargets() sourceSets { commonMain.dependencies { diff --git a/rsocket-transports/ktor-websocket-server/build.gradle.kts b/rsocket-transports/ktor-websocket-server/build.gradle.kts index ae436493..0f7ad5b1 100644 --- a/rsocket-transports/ktor-websocket-server/build.gradle.kts +++ b/rsocket-transports/ktor-websocket-server/build.gradle.kts @@ -24,7 +24,7 @@ description = "rsocket-kotlin ktor WebSocket server transport implementation" kotlin { jvmTarget() - nixTargets() + nativeTargets() sourceSets { commonMain.dependencies { From 3a4c01135f2bff89c9d5110cc0555017275dc04e Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Tue, 12 Nov 2024 00:21:55 +0200 Subject: [PATCH 08/17] Support wasm targets for core, tests and local transport --- ...rsocketbuild.multiplatform-base.gradle.kts | 11 ++++ .../src/main/kotlin/rsocketbuild/targets.kt | 27 +++++++++ rsocket-core/build.gradle.kts | 4 +- .../kotlin/logging/DefaultLoggerFactory.kt | 57 ------------------- .../kotlin/logging/DefaultLoggerFactory.kt | 4 +- rsocket-internal-io/build.gradle.kts | 4 +- rsocket-test/build.gradle.kts | 4 +- .../kotlin/io/rsocket/kotlin/test/Test.kt | 27 +++++++++ .../kotlin/io/rsocket/kotlin/test/Test.kt | 27 +++++++++ rsocket-transport-tests/build.gradle.kts | 4 +- rsocket-transports/local/build.gradle.kts | 4 +- 11 files changed, 99 insertions(+), 74 deletions(-) delete mode 100644 rsocket-core/src/jsMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt rename rsocket-core/src/{nativeMain => nonJvmMain}/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt (85%) create mode 100644 rsocket-test/src/wasmJsMain/kotlin/io/rsocket/kotlin/test/Test.kt create mode 100644 rsocket-test/src/wasmWasiMain/kotlin/io/rsocket/kotlin/test/Test.kt diff --git a/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts b/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts index b5eb9b7e..70140f29 100644 --- a/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts +++ b/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts @@ -41,6 +41,17 @@ kotlin { optIn.addAll(OptIns.ExperimentalSubclassOptIn) } + applyDefaultHierarchyTemplate { + common { + group("nonJvm") { + withJs() + withWasmJs() + withWasmWasi() + group("native") + } + } + } + sourceSets.configureEach { languageSettings { if (name.contains("test", ignoreCase = true)) { diff --git a/build-logic/src/main/kotlin/rsocketbuild/targets.kt b/build-logic/src/main/kotlin/rsocketbuild/targets.kt index 7750833e..ac5c8ae7 100644 --- a/build-logic/src/main/kotlin/rsocketbuild/targets.kt +++ b/build-logic/src/main/kotlin/rsocketbuild/targets.kt @@ -18,8 +18,17 @@ package rsocketbuild import org.gradle.jvm.toolchain.* import org.gradle.kotlin.dsl.* +import org.jetbrains.kotlin.gradle.* import org.jetbrains.kotlin.gradle.dsl.* +fun KotlinMultiplatformExtension.allTargets() { + jvmTarget() + jsTarget() + wasmJsTarget() + wasmWasiTarget() + nativeTargets() +} + fun KotlinMultiplatformExtension.appleTargets() { macosX64() macosArm64() @@ -63,6 +72,24 @@ fun KotlinMultiplatformExtension.jsTarget( } } +@OptIn(ExperimentalWasmDsl::class) +fun KotlinMultiplatformExtension.wasmJsTarget( + supportsNode: Boolean = true, + supportsBrowser: Boolean = true, +) { + wasmJs { + if (supportsNode) nodejs() + if (supportsBrowser) browser() + } +} + +@OptIn(ExperimentalWasmDsl::class) +fun KotlinMultiplatformExtension.wasmWasiTarget() { + wasmWasi { + nodejs() + } +} + fun KotlinMultiplatformExtension.jvmTarget( jdkVersion: Int = 8, jdkAdditionalTestVersions: Set = setOf(11, 17, 21), diff --git a/rsocket-core/build.gradle.kts b/rsocket-core/build.gradle.kts index 87aa8634..dbdf05ef 100644 --- a/rsocket-core/build.gradle.kts +++ b/rsocket-core/build.gradle.kts @@ -24,9 +24,7 @@ plugins { description = "rsocket-kotlin core functionality" kotlin { - jvmTarget() - jsTarget() - nativeTargets() + allTargets() sourceSets { commonMain.dependencies { diff --git a/rsocket-core/src/jsMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt b/rsocket-core/src/jsMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt deleted file mode 100644 index dcde87bc..00000000 --- a/rsocket-core/src/jsMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2015-2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.kotlin.logging - -import io.rsocket.kotlin.* - -@RSocketLoggingApi -internal actual val DefaultLoggerFactory: LoggerFactory - get() = ConsoleLogger - -@RSocketLoggingApi -public class ConsoleLogger( - override val tag: String, - private val minLevel: LoggingLevel = LoggingLevel.INFO, -) : Logger { - override fun isLoggable(level: LoggingLevel): Boolean = level >= minLevel - override fun rawLog(level: LoggingLevel, throwable: Throwable?, message: Any?) { - val meta = "[$level] ($tag)" - when (level) { - LoggingLevel.ERROR -> throwable - ?.let { console.error(meta, message, "Error:", it) } - ?: console.error(meta, message) - LoggingLevel.WARN -> throwable - ?.let { console.warn(meta, message, "Error:", it) } - ?: console.warn(meta, message) - LoggingLevel.INFO -> throwable - ?.let { console.info(meta, message, "Error:", it) } - ?: console.info(meta, message) - LoggingLevel.DEBUG -> throwable - ?.let { console.log(meta, message, "Error:", it) } - ?: console.log(meta, message) - LoggingLevel.TRACE -> throwable - ?.let { console.log(meta, message, "Error:", it) } - ?: console.log(meta, message) - } - } - - public companion object : LoggerFactory { - override fun logger(tag: String): Logger = ConsoleLogger(tag) - - public fun withLevel(minLevel: LoggingLevel): LoggerFactory = LoggerFactory { ConsoleLogger(it, minLevel) } - } -} diff --git a/rsocket-core/src/nativeMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt b/rsocket-core/src/nonJvmMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt similarity index 85% rename from rsocket-core/src/nativeMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt rename to rsocket-core/src/nonJvmMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt index d234e402..ce8db463 100644 --- a/rsocket-core/src/nativeMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt +++ b/rsocket-core/src/nonJvmMain/kotlin/io/rsocket/kotlin/logging/DefaultLoggerFactory.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,5 +19,5 @@ package io.rsocket.kotlin.logging import io.rsocket.kotlin.* @RSocketLoggingApi -public actual val DefaultLoggerFactory: LoggerFactory +internal actual val DefaultLoggerFactory: LoggerFactory get() = PrintLogger diff --git a/rsocket-internal-io/build.gradle.kts b/rsocket-internal-io/build.gradle.kts index 7211178b..4e1e4892 100644 --- a/rsocket-internal-io/build.gradle.kts +++ b/rsocket-internal-io/build.gradle.kts @@ -23,9 +23,7 @@ plugins { description = "rsocket-kotlin internal IO support" kotlin { - jvmTarget() - jsTarget() - nativeTargets() + allTargets() sourceSets { commonMain.dependencies { diff --git a/rsocket-test/build.gradle.kts b/rsocket-test/build.gradle.kts index f15aebc9..c54fc308 100644 --- a/rsocket-test/build.gradle.kts +++ b/rsocket-test/build.gradle.kts @@ -24,9 +24,7 @@ plugins { @OptIn(ExperimentalKotlinGradlePluginApi::class) kotlin { - jvmTarget() - jsTarget() - nativeTargets() + allTargets() compilerOptions { freeCompilerArgs.add("-Xexpect-actual-classes") diff --git a/rsocket-test/src/wasmJsMain/kotlin/io/rsocket/kotlin/test/Test.kt b/rsocket-test/src/wasmJsMain/kotlin/io/rsocket/kotlin/test/Test.kt new file mode 100644 index 00000000..e31d889c --- /dev/null +++ b/rsocket-test/src/wasmJsMain/kotlin/io/rsocket/kotlin/test/Test.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2015-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.rsocket.kotlin.test + +import kotlinx.coroutines.* + +actual annotation class IgnoreJs +actual annotation class IgnoreJvm +actual annotation class IgnoreNative + +actual val anotherDispatcher: CoroutineDispatcher get() = Dispatchers.Default + +actual fun identityHashCode(instance: Any): Int = instance.hashCode() diff --git a/rsocket-test/src/wasmWasiMain/kotlin/io/rsocket/kotlin/test/Test.kt b/rsocket-test/src/wasmWasiMain/kotlin/io/rsocket/kotlin/test/Test.kt new file mode 100644 index 00000000..e31d889c --- /dev/null +++ b/rsocket-test/src/wasmWasiMain/kotlin/io/rsocket/kotlin/test/Test.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2015-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.rsocket.kotlin.test + +import kotlinx.coroutines.* + +actual annotation class IgnoreJs +actual annotation class IgnoreJvm +actual annotation class IgnoreNative + +actual val anotherDispatcher: CoroutineDispatcher get() = Dispatchers.Default + +actual fun identityHashCode(instance: Any): Int = instance.hashCode() diff --git a/rsocket-transport-tests/build.gradle.kts b/rsocket-transport-tests/build.gradle.kts index a2353b56..142b8954 100644 --- a/rsocket-transport-tests/build.gradle.kts +++ b/rsocket-transport-tests/build.gradle.kts @@ -24,9 +24,7 @@ plugins { @OptIn(ExperimentalKotlinGradlePluginApi::class) kotlin { - jvmTarget() - jsTarget() - nativeTargets() + allTargets() compilerOptions { optIn.addAll( diff --git a/rsocket-transports/local/build.gradle.kts b/rsocket-transports/local/build.gradle.kts index f1755711..7f52357a 100644 --- a/rsocket-transports/local/build.gradle.kts +++ b/rsocket-transports/local/build.gradle.kts @@ -24,9 +24,7 @@ plugins { description = "rsocket-kotlin Local transport implementation" kotlin { - jvmTarget() - jsTarget() - nativeTargets() + allTargets() sourceSets { commonMain.dependencies { From 4901db10d884fb60eb9716b0b59f301c5d041fe5 Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Tue, 12 Nov 2024 00:29:11 +0200 Subject: [PATCH 09/17] Support wasm-js target in ktor-client modules --- .../main/kotlin/rsocketbuild.multiplatform-base.gradle.kts | 5 +---- ktor-plugins/ktor-client-rsocket/build.gradle.kts | 1 + ktor-plugins/rsocket-ktor-client/build.gradle.kts | 1 + rsocket-transports/ktor-websocket-client/build.gradle.kts | 1 + rsocket-transports/ktor-websocket-internal/build.gradle.kts | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts b/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts index 70140f29..5bf4bd64 100644 --- a/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts +++ b/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts @@ -32,10 +32,7 @@ plugins { @OptIn(ExperimentalKotlinGradlePluginApi::class) kotlin { compilerOptions { - // because of INVISIBLE_REFERENCE suppression - will be removed after migration to kotlinx.io - if (project.name != "rsocket-test") { - allWarningsAsErrors.set(true) - } + allWarningsAsErrors.set(true) progressiveMode.set(true) freeCompilerArgs.add("-Xrender-internal-diagnostic-names") optIn.addAll(OptIns.ExperimentalSubclassOptIn) diff --git a/ktor-plugins/ktor-client-rsocket/build.gradle.kts b/ktor-plugins/ktor-client-rsocket/build.gradle.kts index 9d9b43f8..2122bd12 100644 --- a/ktor-plugins/ktor-client-rsocket/build.gradle.kts +++ b/ktor-plugins/ktor-client-rsocket/build.gradle.kts @@ -25,6 +25,7 @@ description = "rsocket-kotlin ktor client plugin" kotlin { jvmTarget() jsTarget() + wasmJsTarget() nativeTargets() sourceSets { diff --git a/ktor-plugins/rsocket-ktor-client/build.gradle.kts b/ktor-plugins/rsocket-ktor-client/build.gradle.kts index 3312f542..5bbe92fe 100644 --- a/ktor-plugins/rsocket-ktor-client/build.gradle.kts +++ b/ktor-plugins/rsocket-ktor-client/build.gradle.kts @@ -25,6 +25,7 @@ description = "OLD ARTIFACT - migrate to ktor-client-rsocket" kotlin { jvmTarget() jsTarget() + wasmJsTarget() nativeTargets() sourceSets { diff --git a/rsocket-transports/ktor-websocket-client/build.gradle.kts b/rsocket-transports/ktor-websocket-client/build.gradle.kts index f9bcbf6a..7aae725b 100644 --- a/rsocket-transports/ktor-websocket-client/build.gradle.kts +++ b/rsocket-transports/ktor-websocket-client/build.gradle.kts @@ -25,6 +25,7 @@ description = "rsocket-kotlin ktor WebSocket client transport implementation" kotlin { jvmTarget() jsTarget() + wasmJsTarget() nativeTargets() sourceSets { diff --git a/rsocket-transports/ktor-websocket-internal/build.gradle.kts b/rsocket-transports/ktor-websocket-internal/build.gradle.kts index c3583f62..42aeb76d 100644 --- a/rsocket-transports/ktor-websocket-internal/build.gradle.kts +++ b/rsocket-transports/ktor-websocket-internal/build.gradle.kts @@ -25,6 +25,7 @@ description = "rsocket-kotlin ktor WebSocket transport utilities" kotlin { jvmTarget() jsTarget() + wasmJsTarget() nativeTargets() sourceSets { From 514eb2716bf40f4768ba4eac4ebe4e00b73cb183 Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Sun, 1 Dec 2024 15:29:13 +0200 Subject: [PATCH 10/17] use "127.0.0.1" instead of "0.0.0.0" in ktor tcp server tests because of mingw/windows behaviour --- .../io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt | 2 +- .../io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt b/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt index 732768b7..005f7811 100644 --- a/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt +++ b/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt @@ -25,7 +25,7 @@ import kotlin.test.* class TcpServerTest : SuspendTest { private val testJob = Job() private val testContext = testJob + TestExceptionHandler - private val serverTransport = KtorTcpServerTransport(testContext).target() + private val serverTransport = KtorTcpServerTransport(testContext).target("127.0.0.1") private fun KtorTcpServerInstance.clientTransport() = KtorTcpClientTransport(testContext).target(localAddress) diff --git a/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt b/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt index 72682ce3..1b2e9e1a 100644 --- a/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt +++ b/rsocket-transports/ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt @@ -24,7 +24,7 @@ import kotlinx.coroutines.* @Suppress("DEPRECATION_ERROR") class TcpTransportTest : TransportTest() { override suspend fun before() { - val serverSocket = startServer(TcpServerTransport()).serverSocket.await() + val serverSocket = startServer(TcpServerTransport("127.0.0.1")).serverSocket.await() client = connectClient(TcpClientTransport(serverSocket.localAddress as InetSocketAddress, testContext)) } } @@ -36,7 +36,7 @@ class KtorTcpTransportTest : TransportTest() { override suspend fun before() { val server = startServer(KtorTcpServerTransport(testContext) { selectorManager(selector, false) - }.target()) + }.target("127.0.0.1")) client = connectClient(KtorTcpClientTransport(testContext) { selectorManager(selector, false) }.target(server.localAddress)) From b732525f1319007c5e8af0f74f7b777bff9ac64b Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Sun, 1 Dec 2024 16:03:48 +0200 Subject: [PATCH 11/17] run wasm tests --- .github/workflows/run-tests.yml | 2 +- .../main/kotlin/rsocketbuild.multiplatform-base.gradle.kts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0030a4bb..c77f2cdf 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -33,7 +33,7 @@ jobs: fail-fast: false matrix: os: [ 'ubuntu-latest' ] - target: [ 'jvm', 'jvm11', 'jvm17', 'jvm21', 'js', 'native' ] + target: [ 'jvmAll', 'jsAndWasm', 'native' ] include: - os: 'macos-latest' target: 'macos' diff --git a/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts b/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts index 5bf4bd64..fe25fefe 100644 --- a/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts +++ b/build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.gradle.* import org.jetbrains.kotlin.gradle.plugin.* import org.jetbrains.kotlin.gradle.plugin.mpp.* import org.jetbrains.kotlin.gradle.targets.js.ir.* +import org.jetbrains.kotlin.gradle.targets.js.testing.* import org.jetbrains.kotlin.gradle.targets.jvm.* import org.jetbrains.kotlin.gradle.targets.jvm.tasks.* import org.jetbrains.kotlin.gradle.targets.native.tasks.* @@ -111,6 +112,12 @@ registerTestAggregationTask( targetFilter = { it.platformType == KotlinPlatformType.jvm } ) +registerTestAggregationTask( + name = "jsAndWasmTest", + taskDependencies = { tasks.withType() }, + targetFilter = { it.platformType == KotlinPlatformType.js || it.platformType == KotlinPlatformType.wasm } +) + registerTestAggregationTask( name = "nativeTest", taskDependencies = { tasks.withType().matching { it.enabled } }, From 4ca305d5b86b51095d19e3d0851d73b97933a1c7 Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Fri, 6 Dec 2024 08:21:35 +0200 Subject: [PATCH 12/17] enable all transport tests --- .../kotlin/transport/tests/TransportTest.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/rsocket-transport-tests/src/commonMain/kotlin/io/rsocket/kotlin/transport/tests/TransportTest.kt b/rsocket-transport-tests/src/commonMain/kotlin/io/rsocket/kotlin/transport/tests/TransportTest.kt index 59b9fa05..4264f4d5 100644 --- a/rsocket-transport-tests/src/commonMain/kotlin/io/rsocket/kotlin/transport/tests/TransportTest.kt +++ b/rsocket-transport-tests/src/commonMain/kotlin/io/rsocket/kotlin/transport/tests/TransportTest.kt @@ -121,7 +121,7 @@ abstract class TransportTest : SuspendTest { } @Test - @Ignore //flaky, ignore for now + //@Ignore //flaky, ignore for now fun requestChannel20000() = test { val request = flow { repeat(20_000) { emit(payload(7)) } @@ -134,7 +134,7 @@ abstract class TransportTest : SuspendTest { } @Test - @Ignore //flaky, ignore for now + //@Ignore //flaky, ignore for now fun requestChannel200000() = test { val request = flow { repeat(200_000) { emit(payload(it)) } @@ -148,7 +148,7 @@ abstract class TransportTest : SuspendTest { } @Test - @Ignore //flaky, ignore for now + //@Ignore //flaky, ignore for now fun requestChannel16x256() = test { val request = flow { repeat(256) { @@ -164,7 +164,7 @@ abstract class TransportTest : SuspendTest { } @Test - @Ignore //flaky, ignore for now + //@Ignore //flaky, ignore for now fun requestChannel256x512() = test { val request = flow { repeat(512) { @@ -180,7 +180,7 @@ abstract class TransportTest : SuspendTest { } @Test - @IgnoreNative // slow test + //@IgnoreNative // slow test fun requestStreamX16() = test { (0..16).map { async { @@ -191,7 +191,7 @@ abstract class TransportTest : SuspendTest { } @Test - @Ignore //flaky, ignore for now + //@Ignore //flaky, ignore for now fun requestStreamX256() = test { (0..256).map { async { @@ -202,7 +202,7 @@ abstract class TransportTest : SuspendTest { } @Test - @IgnoreNative //flaky, ignore for now + //@IgnoreNative //flaky, ignore for now fun requestChannel500NoLeak() = test { val request = flow { repeat(10_000) { emitOrClose(payload(3)) } @@ -241,13 +241,13 @@ abstract class TransportTest : SuspendTest { } @Test - @IgnoreNative //flaky, ignore for now + //@IgnoreNative //flaky, ignore for now fun requestResponse10000() = test { (1..10000).map { async { client.requestResponse(payload(3)).let(Companion::checkPayload) } }.awaitAll() } @Test - @Ignore //flaky, ignore for now + //@Ignore //flaky, ignore for now fun requestResponse100000() = test { repeat(100000) { client.requestResponse(payload(3)).let(Companion::checkPayload) } } @@ -260,14 +260,14 @@ abstract class TransportTest : SuspendTest { } @Test - @IgnoreNative + //@IgnoreNative fun requestStream8K() = test { val count = client.requestStream(payload(3)).onEach { checkPayload(it) }.count() assertEquals(8192, count) // TODO } @Test - @IgnoreNative + //@IgnoreNative fun requestStream500NoLeak() = test { val count = client From 52a03bd13aea960688225bfdc494f5d9f86d069b Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Fri, 6 Dec 2024 09:25:34 +0200 Subject: [PATCH 13/17] no timeout --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index c77f2cdf..b05a7080 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -50,7 +50,7 @@ jobs: - uses: ./.github/actions/setup-gradle - run: ./gradlew ${{ matrix.target }}Test --continue - timeout-minutes: 30 + # timeout-minutes: 30 - if: always() && !cancelled() uses: actions/upload-artifact@v4 From 246e71f37ff8f047fbe82986afad4304229c1f22 Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Fri, 6 Dec 2024 10:20:41 +0200 Subject: [PATCH 14/17] bigger timeouts --- .../kotlin/io/rsocket/kotlin/transport/tests/TransportTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rsocket-transport-tests/src/commonMain/kotlin/io/rsocket/kotlin/transport/tests/TransportTest.kt b/rsocket-transport-tests/src/commonMain/kotlin/io/rsocket/kotlin/transport/tests/TransportTest.kt index 4264f4d5..2375ed75 100644 --- a/rsocket-transport-tests/src/commonMain/kotlin/io/rsocket/kotlin/transport/tests/TransportTest.kt +++ b/rsocket-transport-tests/src/commonMain/kotlin/io/rsocket/kotlin/transport/tests/TransportTest.kt @@ -32,7 +32,7 @@ import kotlin.time.Duration.Companion.seconds //TODO: need to somehow rework those tests, as now they are super flaky abstract class TransportTest : SuspendTest { - override val testTimeout: Duration = 3.minutes + override val testTimeout: Duration = 10.minutes private val testJob = SupervisorJob() protected val testContext = testJob + TestExceptionHandler From 4ececa684d29ba89f7c7b63633b0059f5f3ce534 Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Fri, 6 Dec 2024 10:20:59 +0200 Subject: [PATCH 15/17] run tests --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b05a7080..5d0e6cd9 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -33,7 +33,7 @@ jobs: fail-fast: false matrix: os: [ 'ubuntu-latest' ] - target: [ 'jvmAll', 'jsAndWasm', 'native' ] + target: [ 'jvm', 'jvm11', 'jvm17', 'jvm21', 'jsAndWasm', 'native' ] include: - os: 'macos-latest' target: 'macos' From f9a1cf1e5b5b819a725e34b255ff61a1e75e6214 Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Tue, 10 Dec 2024 00:26:18 +0200 Subject: [PATCH 16/17] try to run mingw tests not in parallel --- .github/workflows/run-tests.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 5d0e6cd9..99a2bef3 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -49,8 +49,11 @@ jobs: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-gradle - - run: ./gradlew ${{ matrix.target }}Test --continue - # timeout-minutes: 30 + - if: ${{ matrix.os != 'windows-latest' }} + run: ./gradlew ${{ matrix.target }}Test --continue + + - if: ${{ matrix.os == 'windows-latest' }} + run: ./gradlew ${{ matrix.target }}Test --continue --max-workers=1 - if: always() && !cancelled() uses: actions/upload-artifact@v4 From c42960b706a91d62e1767b363efba408493d19b6 Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Tue, 10 Dec 2024 08:47:52 +0200 Subject: [PATCH 17/17] add flushIfNeeded --- .../io/rsocket/kotlin/transport/ktor/tcp/KtorTcpConnection.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rsocket-transports/ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/KtorTcpConnection.kt b/rsocket-transports/ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/KtorTcpConnection.kt index a07d44e3..ccc08958 100644 --- a/rsocket-transports/ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/KtorTcpConnection.kt +++ b/rsocket-transports/ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/KtorTcpConnection.kt @@ -92,9 +92,10 @@ private class KtorTcpConnection( } @OptIn(InternalAPI::class) -private fun ByteWriteChannel.writeFrame(frame: Buffer) { +private suspend fun ByteWriteChannel.writeFrame(frame: Buffer) { writeBuffer.writeInt24(frame.size.toInt()) writeBuffer.transferFrom(frame) + flushIfNeeded() } @OptIn(InternalAPI::class)