Skip to content

Commit

Permalink
Add support for all targets in pure Kotlin modules, and unix targets …
Browse files Browse the repository at this point in the history
…in Ktor modules

Resolves:
#234
  • Loading branch information
joffrey-bion committed Jun 14, 2022
1 parent de95246 commit c177062
Show file tree
Hide file tree
Showing 30 changed files with 282 additions and 70 deletions.
48 changes: 45 additions & 3 deletions autobahn-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ kotlin {
jsWithBigTimeouts("jsKtor1")
jsWithBigTimeouts("jsKtor2")
jsWithBigTimeouts("jsOther")
setupNativeTargets()
nativeTargets()

sourceSets {
val commonTest by getting {
Expand Down Expand Up @@ -107,12 +107,45 @@ kotlin {

setupNativeSourceSets()

val nativeDarwinTest by getting {
val nativeTest by getting {
dependencies {
implementation(projects.krossbowWebsocketBuiltin)
// necessary for HTTP get implementation
implementation(libs.ktor2.client.core)
}
}

val unixTest by getting {
dependencies {
implementation(projects.krossbowWebsocketKtor)
implementation(libs.ktor2.client.cio)
}
}

val mingwX64Test by getting {
dependencies {
implementation(projects.krossbowWebsocketKtor)
implementation(libs.ktor2.client.curl)
}
}

val darwinTest by getting {
dependencies {
// necessary for HTTP get implementation
implementation(libs.ktor2.client.darwin)
}
}
val darwinBuiltinTest by creating {
dependsOn(darwinTest)
dependencies {
implementation(projects.krossbowWebsocketBuiltin)
}
}
val darwinKtor2Test by creating {
dependsOn(darwinTest)
dependencies {
implementation(projects.krossbowWebsocketKtor)
}
}
}
}

Expand Down Expand Up @@ -141,6 +174,15 @@ tasks.withType<org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest> {
}
}

tasks.withType<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest> {
doFirst {
val autobahnContainer = getAutobahnTestServerContainerInfo()
environment("AUTOBAHN_SERVER_HOST", autobahnContainer.host)
environment("AUTOBAHN_SERVER_TCP_8080", autobahnContainer.ports.getValue(8080))
environment("AUTOBAHN_SERVER_TCP_9001", autobahnContainer.ports.getValue(9001))
}
}

tasks.withType<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest> {
doFirst {
val autobahnContainer = getAutobahnTestServerContainerInfo()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.hildan.krossbow.websocket.test.autobahn

import org.hildan.krossbow.websocket.WebSocketClient
import org.hildan.krossbow.websocket.darwin.DarwinWebSocketClient

class KtorDarwinWebSocketAutobahnTest : AutobahnClientTestSuite("krossbow-darwin-client-${Platform.osFamily.name.lowercase()}") {

override fun provideClient(): WebSocketClient = KtorWebSocketClient(HttpClient(Darwin) { install(WebSockets) })
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.hildan.krossbow.websocket.test.autobahn

import io.ktor.client.engine.*
import io.ktor.client.engine.darwin.*

actual fun ktorEngine(): HttpClientEngineFactory<*> = Darwin
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.hildan.krossbow.websocket.test.autobahn

import io.ktor.client.engine.*
import io.ktor.client.engine.cio.*

actual fun ktorEngine(): HttpClientEngineFactory<*> = CIO
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.hildan.krossbow.websocket.test.autobahn

import io.ktor.client.engine.*
import io.ktor.client.engine.curl.*

actual fun ktorEngine(): HttpClientEngineFactory<*> = Curl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.hildan.krossbow.websocket.test.autobahn.org.hildan.krossbow.websocket.test.autobahn

import io.ktor.client.*
import io.ktor.client.engine.curl.*
import io.ktor.client.plugins.websocket.*
import org.hildan.krossbow.websocket.WebSocketClient
import org.hildan.krossbow.websocket.ktor.KtorWebSocketClient
import org.hildan.krossbow.websocket.test.autobahn.AutobahnClientTestSuite

class KtorCurlWebSocketAutobahnTest : AutobahnClientTestSuite(
agentUnderTest = "krossbow-ktor-curl-client-${Platform.osFamily.name.lowercase()}",
) {
override fun provideClient(): WebSocketClient = KtorWebSocketClient(HttpClient(Curl) { install(WebSockets) })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package org.hildan.krossbow.websocket.test.autobahn

import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.darwin.*
import io.ktor.client.engine.*
import io.ktor.client.request.*

actual class HttpGetter {
private val client = HttpClient(Darwin)
private val client = HttpClient(ktorEngine())

actual suspend fun get(url: String): String = client.get(url).body()
}

expect fun ktorEngine(): HttpClientEngineFactory<*>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.hildan.krossbow.websocket.test.autobahn

import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.websocket.*
import org.hildan.krossbow.websocket.WebSocketClient
import org.hildan.krossbow.websocket.ktor.KtorWebSocketClient

class KtorCioWebSocketAutobahnTest : AutobahnClientTestSuite(
agentUnderTest = "krossbow-ktor-cio-client-${Platform.osFamily.name.lowercase()}",
exclusions = listOf(
CaseExclusion(
caseIdPrefixes = listOf("2.5"),
reason = "CIO is more lenient than the spec, and accept pings > 125 bytes",
),
CaseExclusion(
caseIdPrefixes = listOf("3.1", "3.2", "3.3", "3.4", "3.5", "3.6"),
reason = "CIO is more lenient than the spec, and doesn't fail on non-negotiated RSV != 0",
),
CaseExclusion(
caseIdPrefixes = listOf("5.1"),
reason = "CIO is more lenient than the spec, and doesn't fail on fragmented pings",
),
// FIXME this is not critical but should be investigated
CaseExclusion(
caseIdPrefixes = listOf("5.7"),
reason = "wrong ordering in case of mixed pings with fragmented messages",
),
),
) {
override fun provideClient(): WebSocketClient = KtorWebSocketClient(HttpClient(CIO) { install(WebSockets) })
}
140 changes: 110 additions & 30 deletions buildSrc/src/main/kotlin/SourceSets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,44 @@ import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.getting
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl

fun KotlinMultiplatformExtension.jsTargets() {
js(BOTH) {
browser()
nodejs()
}
}

fun KotlinMultiplatformExtension.jsWithBigTimeouts(name: String = "js") {
js(name, BOTH) {
useCommonJs()
nodejs {
testTask {
useMocha {
timeout = "10s"
}
nodejsWithBigTimeout()
browserWithBigTimeout()
}
}

fun KotlinJsTargetDsl.nodejsWithBigTimeout() {
nodejs {
testTask {
useMocha {
timeout = "10s"
}
}
browser {
testTask {
useMocha {
timeout = "10s"
}
}
}

fun KotlinJsTargetDsl.browserWithBigTimeout() {
browser {
testTask {
useMocha {
timeout = "10s"
}
}
}
}

fun KotlinMultiplatformExtension.setupNativeTargets() {
fun KotlinMultiplatformExtension.darwinTargets() {
ios()
iosSimulatorArm64()

Expand All @@ -38,13 +54,17 @@ fun KotlinMultiplatformExtension.setupNativeTargets() {
watchosX86()
watchosSimulatorArm64()

// Desktop not supported yet
// macosX64()
// linuxX64()
// mingwX64()
macosX64()
}

fun NamedDomainObjectContainer<KotlinSourceSet>.setupNativeSourceSets() {
fun KotlinMultiplatformExtension.nativeTargets() {
darwinTargets()

linuxX64()
mingwX64()
}

fun NamedDomainObjectContainer<KotlinSourceSet>.setupDarwinSourceSets() {
val commonMain by getting {}
val commonTest by getting {}

Expand All @@ -55,18 +75,18 @@ fun NamedDomainObjectContainer<KotlinSourceSet>.setupNativeSourceSets() {
dependsOn(commonTest)
}

val nativeDarwinMain by creating {
val darwinMain by creating {
dependsOn(nativeMain)
}
val nativeDarwinTest by creating {
val darwinTest by creating {
dependsOn(nativeTest)
}

val iosMain by getting {
dependsOn(nativeDarwinMain)
dependsOn(darwinMain)
}
val iosTest by getting {
dependsOn(nativeDarwinTest)
dependsOn(darwinTest)
}

val iosSimulatorArm64Main by getting {
Expand All @@ -77,36 +97,36 @@ fun NamedDomainObjectContainer<KotlinSourceSet>.setupNativeSourceSets() {
}

val watchosX86Main by getting {
dependsOn(nativeDarwinMain)
dependsOn(darwinMain)
}
val watchosX86Test by getting {
dependsOn(nativeDarwinTest)
dependsOn(darwinTest)
}
val watchosArm32Main by getting {
dependsOn(nativeDarwinMain)
dependsOn(darwinMain)
}
val watchosArm32Test by getting {
dependsOn(nativeDarwinTest)
dependsOn(darwinTest)
}
val watchosArm64Main by getting {
dependsOn(nativeDarwinMain)
dependsOn(darwinMain)
}
val watchosArm64Test by getting {
dependsOn(nativeDarwinTest)
dependsOn(darwinTest)
}

val watchosSimulatorArm64Main by getting {
dependsOn(nativeDarwinMain)
dependsOn(darwinMain)
}
val watchosSimulatorArm64Test by getting {
dependsOn(nativeDarwinTest)
dependsOn(darwinTest)
}

val tvosMain by getting {
dependsOn(nativeDarwinMain)
dependsOn(darwinMain)
}
val tvosTest by getting {
dependsOn(nativeDarwinTest)
dependsOn(darwinTest)
}

val tvosSimulatorArm64Main by getting {
Expand All @@ -115,4 +135,64 @@ fun NamedDomainObjectContainer<KotlinSourceSet>.setupNativeSourceSets() {
val tvosSimulatorArm64Test by getting {
dependsOn(tvosTest)
}

val macosX64Main by getting {
dependsOn(darwinMain)
}
val macosX64Test by getting {
dependsOn(darwinTest)
}
}

fun NamedDomainObjectContainer<KotlinSourceSet>.setupNativeSourceSets() {
setupDarwinSourceSets()

val nativeMain by getting {}
val nativeTest by getting {}

val unixMain by creating {
dependsOn(nativeMain)
}
val unixTest by creating {
dependsOn(nativeTest)
}

val darwinMain by getting {
dependsOn(unixMain)
}
val darwinTest by getting {
dependsOn(unixTest)
}

val desktopMain by creating {
dependsOn(nativeMain)
}
val desktopTest by creating {
dependsOn(nativeTest)
}

val linuxX64Main by getting {
dependsOn(unixMain)
dependsOn(desktopMain)
}
val linuxX64Test by getting {
dependsOn(unixTest)
dependsOn(desktopTest)
}

val macosX64Main by getting {
dependsOn(unixMain)
dependsOn(desktopMain)
}
val macosX64Test by getting {
dependsOn(unixTest)
dependsOn(desktopTest)
}

val mingwX64Main by getting {
dependsOn(desktopMain)
}
val mingwX64Test by getting {
dependsOn(desktopTest)
}
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ ktor1-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "kt
ktor1-client-serialization = { module = "io.ktor:ktor-client-serialization", version.ref = "ktor1" }
ktor1-client-websockets = { module = "io.ktor:ktor-client-websockets", version.ref = "ktor1" }
ktor2-client-contentNegotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor2" }
ktor2-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor2" }
ktor2-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor2" }
ktor2-client-curl = { module = "io.ktor:ktor-client-curl", version.ref = "ktor2" }
ktor2-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor2" }
ktor2-client-java = { module = "io.ktor:ktor-client-java", version.ref = "ktor2" }
ktor2-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor2" }
Expand Down
Loading

0 comments on commit c177062

Please sign in to comment.