Skip to content

improves client side tests #179

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

Merged
merged 1 commit into from Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gradle-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
dependencies-cache-enabled: false
configuration-cache-enabled: false
- name: Test rsocket-transport-ktor module
if: matrix.target != 'mingwX64' && matrix.target != 'jsIrNode' && matrix.target != 'jsIrBrowser' && matrix.target != 'jsLegacyNode' && matrix.target != 'jsLegacyBrowser' && (success() || failure())
if: matrix.target != 'mingwX64' && (success() || failure())
timeout-minutes: 10
uses: gradle/gradle-build-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gradle-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
dependencies-cache-enabled: false
configuration-cache-enabled: false
- name: Test rsocket-transport-ktor module
if: matrix.target != 'mingwX64' && matrix.target != 'jsIrNode' && matrix.target != 'jsIrBrowser' && matrix.target != 'jsLegacyNode' && matrix.target != 'jsLegacyBrowser' && (success() || failure())
if: matrix.target != 'mingwX64' && (success() || failure())
timeout-minutes: 10
uses: gradle/gradle-build-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
dependencies-cache-enabled: false
configuration-cache-enabled: false
- name: Test rsocket-transport-ktor module
if: matrix.target != 'mingwX64' && matrix.target != 'jsIrNode' && matrix.target != 'jsIrBrowser' && matrix.target != 'jsLegacyNode' && matrix.target != 'jsLegacyBrowser' && (success() || failure())
if: matrix.target != 'mingwX64' && (success() || failure())
timeout-minutes: 10
uses: gradle/gradle-build-action@v1
with:
Expand Down
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ subprojects {
//targets configuration
extensions.configure<KotlinMultiplatformExtension> {
val isAutoConfigurable = project.name.startsWith("rsocket") //manual config of others
val jvmOnly = project.name == "rsocket-transport-ktor-server" //server is jvm only

val jvmOnly =
project.name == "rsocket-transport-ktor-server" || //server is jvm only
project.name == "rsocket-test-server"
//windows target isn't supported by ktor-network
val supportMingw = project.name != "rsocket-transport-ktor" && project.name != "rsocket-transport-ktor-client"

Expand Down Expand Up @@ -140,7 +141,7 @@ subprojects {

//common configuration
extensions.configure<KotlinMultiplatformExtension> {
val isTestProject = project.name == "rsocket-test"
val isTestProject = project.name == "rsocket-test" || project.name == "rsocket-test-server"
val isLibProject = project.name.startsWith("rsocket")
val isPlaygroundProject = project.name == "playground"
val isExampleProject = "examples" in project.path
Expand Down
2 changes: 1 addition & 1 deletion examples/multiplatform-chat/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ kotlin {
val clientJsMain by getting {
dependsOn(clientMain)
dependencies {
implementation("io.ktor:ktor-client-js:$ktorVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
}
}

Expand Down
7 changes: 2 additions & 5 deletions playground/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ kotlin {
implementation(project(":rsocket-core"))
implementation(project(":rsocket-transport-local"))
implementation(project(":rsocket-transport-ktor-client"))

implementation("io.ktor:ktor-client-core:$ktorVersion") //for WS support
}
}
val jvmMain by getting {
Expand All @@ -56,10 +58,5 @@ kotlin {
implementation("io.ktor:ktor-server-cio:$ktorVersion")
}
}
val jsMain by getting {
dependencies {
implementation("io.ktor:ktor-client-js:$ktorVersion") //for WS support
}
}
}
}
87 changes: 87 additions & 0 deletions rsocket-test/rsocket-test-server/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2015-2020 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.
*/

import org.jetbrains.kotlin.gradle.plugin.mpp.*
import java.io.*
import java.net.*

plugins {
kotlin("multiplatform")
}

val ktorVersion: String by rootProject

kotlin {
sourceSets {
val jvmMain by getting {
dependencies {
implementation(project(":rsocket-test"))
implementation(project(":rsocket-transport-ktor-server"))

implementation("io.ktor:ktor-server-cio:$ktorVersion")
}
}
}
}

open class RSocketTestServer : DefaultTask() {
@Internal
var server: Closeable? = null
private set

@Internal
lateinit var classpath: FileCollection

@TaskAction
fun exec() {
try {
println("[TestServer] start")
val loader = URLClassLoader(classpath.map { it.toURI().toURL() }.toTypedArray(), ClassLoader.getSystemClassLoader())
server = loader.loadClass("io.rsocket.kotlin.test.server.AppKt").getMethod("start").invoke(null) as Closeable
println("[TestServer] started")
} catch (cause: Throwable) {
println("[TestServer] failed: ${cause.message}")
cause.printStackTrace()
}
}
}

val startTestServer by tasks.registering(RSocketTestServer::class) {
dependsOn(tasks["jvmJar"])
classpath = (kotlin.targets["jvm"].compilations["test"] as KotlinJvmCompilation).runtimeDependencyFiles
}

val testTasks = setOf(
"jsLegacyNodeTest",
"jsIrNodeTest",
"jsLegacyBrowserTest",
"jsIrBrowserTest",
)

rootProject.allprojects {
if (name == "rsocket-transport-ktor") {
tasks.matching { it.name in testTasks }.all {
dependsOn(startTestServer)
}
}
}

gradle.buildFinished {
startTestServer.get().server?.run {
close()
println("[TestServer] stop")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2015-2020 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.server

import io.ktor.application.*
import io.ktor.routing.*
import io.ktor.server.cio.*
import io.ktor.server.engine.*
import io.ktor.websocket.*
import io.rsocket.kotlin.core.*
import io.rsocket.kotlin.test.*
import io.rsocket.kotlin.transport.ktor.*
import io.rsocket.kotlin.transport.ktor.server.*
import kotlinx.coroutines.*
import java.io.*

fun main() {
start().await()
}

fun start(): TestServer {
val server = TestServer()
server.start()
return server
}

class TestServer : Closeable {
private val job = Job()
private var wsServer: ApplicationEngine? = null
private val rSocketServer = RSocketServer {
// loggerFactory = PrintLogger.withLevel(LoggingLevel.DEBUG)
}

fun start(): Unit = runCatching {
val scope = CoroutineScope(job)

//start TCP server
rSocketServer.bindIn(scope, TcpServerTransport(port = 8000)) { TestRSocket() }

//start WS server
wsServer = scope.embeddedServer(CIO, port = 9000) {
install(WebSockets)
install(RSocketSupport) { server = rSocketServer }

routing {
rSocket { TestRSocket() }
}
}.start()

Thread.sleep(1000) //await start
}.onFailure { close() }.getOrThrow()

fun await() {
runBlocking { job.join() }
}

override fun close() {
runBlocking { job.cancelAndJoin() }
wsServer?.stop(0, 1000)
}
}
2 changes: 2 additions & 0 deletions rsocket-transport-ktor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ kotlin {
}

description = "Ktor RSocket transport implementations (TCP, Websocket)"

evaluationDependsOn(":rsocket-test-server")
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2015-2020 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.transport.ktor

import io.ktor.client.*
import io.ktor.client.engine.js.*
import io.ktor.client.features.websocket.*
import io.rsocket.kotlin.test.*
import io.rsocket.kotlin.transport.ktor.client.*
import kotlinx.coroutines.*

class ClientWebSocketTransportTest : TransportTest() {

private val httpClient = HttpClient(Js) {
install(WebSockets)
install(RSocketSupport) { connector = CONNECTOR }
}

override suspend fun before() {
client = httpClient.rSocket(port = 9000)
}

override suspend fun after() {
super.after()
httpClient.close()
httpClient.coroutineContext.job.cancelAndJoin()
}

}
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ include("playground")

include("rsocket-core")
include("rsocket-test")
include("rsocket-test-server")
project(":rsocket-test-server").projectDir = file("rsocket-test/rsocket-test-server")

include("rsocket-transport-local")

Expand Down