diff --git a/rsocket-ktor/server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketConnectionTest.kt b/rsocket-ktor/server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketConnectionTest.kt index b1d68683..83c42278 100644 --- a/rsocket-ktor/server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketConnectionTest.kt +++ b/rsocket-ktor/server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketConnectionTest.kt @@ -26,7 +26,6 @@ import io.rsocket.kotlin.ktor.client.* import io.rsocket.kotlin.ktor.server.* import io.rsocket.kotlin.payload.* import io.rsocket.kotlin.test.* -import io.rsocket.kotlin.transport.tests.* import kotlinx.coroutines.* import kotlinx.coroutines.flow.* import kotlin.test.* @@ -38,7 +37,6 @@ import io.rsocket.kotlin.ktor.client.RSocketSupport as ClientRSocketSupport import io.rsocket.kotlin.ktor.server.RSocketSupport as ServerRSocketSupport class WebSocketConnectionTest : SuspendTest, TestWithLeakCheck { - private val port = PortProvider.next() private val client = HttpClient(ClientCIO) { install(ClientWebSockets) install(ClientRSocketSupport) { @@ -52,7 +50,7 @@ class WebSocketConnectionTest : SuspendTest, TestWithLeakCheck { private var responderJob: Job? = null - private val server = embeddedServer(ServerCIO, port) { + private val server = embeddedServer(ServerCIO, port = 0) { install(ServerWebSockets) install(ServerRSocketSupport) { server = TestServer() @@ -87,6 +85,7 @@ class WebSocketConnectionTest : SuspendTest, TestWithLeakCheck { @Test fun testWorks() = test { + val port = server.resolvedConnectors().single().port val rSocket = client.rSocket(port = port) val requesterJob = rSocket.coroutineContext.job 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 f7065fbf..95667dfb 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 @@ -19,16 +19,17 @@ package io.rsocket.kotlin.transport.ktor.tcp import io.ktor.network.sockets.* import io.rsocket.kotlin.* import io.rsocket.kotlin.test.* -import io.rsocket.kotlin.transport.tests.* import kotlinx.coroutines.* import kotlin.test.* class TcpServerTest : SuspendTest, TestWithLeakCheck { private val testJob = Job() private val testContext = testJob + TestExceptionHandler - private val address = InetSocketAddress("0.0.0.0", PortProvider.next()) - private val serverTransport = TcpServerTransport(address) - private val clientTransport = TcpClientTransport(address, testContext) + private val serverTransport = TcpServerTransport() + private suspend fun clientTransport(server: TcpServer) = TcpClientTransport( + server.serverSocket.await().localAddress as InetSocketAddress, + testContext + ) override suspend fun after() { testJob.cancelAndJoin() @@ -50,7 +51,7 @@ class TcpServerTest : SuspendTest, TestWithLeakCheck { payload(text) } } - }.connect(clientTransport) + }.connect(clientTransport(server)) val client1 = newClient("ok") client1.requestResponse(payload("ok")).close() @@ -86,7 +87,7 @@ class TcpServerTest : SuspendTest, TestWithLeakCheck { }.also { handlers += it } }.also { it.serverSocket.await() } - suspend fun newClient() = TestConnector().connect(clientTransport) + suspend fun newClient() = TestConnector().connect(clientTransport(server)) val client1 = newClient() 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 d2410604..a55440e5 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 @@ -21,8 +21,7 @@ import io.rsocket.kotlin.transport.tests.* class TcpTransportTest : TransportTest() { override suspend fun before() { - val address = InetSocketAddress("0.0.0.0", PortProvider.next()) - startServer(TcpServerTransport(address)).serverSocket.await() - client = connectClient(TcpClientTransport(address, testContext)) + val serverSocket = startServer(TcpServerTransport()).serverSocket.await() + client = connectClient(TcpClientTransport(serverSocket.localAddress as InetSocketAddress, testContext)) } } diff --git a/rsocket-transports/ktor-websocket-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/CIOWebSocketTransportTest.kt b/rsocket-transports/ktor-websocket-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/CIOWebSocketTransportTest.kt index 08f5f81d..850b3cd0 100644 --- a/rsocket-transports/ktor-websocket-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/CIOWebSocketTransportTest.kt +++ b/rsocket-transports/ktor-websocket-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/CIOWebSocketTransportTest.kt @@ -16,31 +16,7 @@ package io.rsocket.kotlin.transport.ktor.websocket.server -import io.rsocket.kotlin.test.* -import kotlin.test.* -import kotlin.time.* -import kotlin.time.Duration.Companion.minutes import io.ktor.client.engine.cio.CIO as ClientCIO import io.ktor.server.cio.CIO as ServerCIO -class CIOWebSocketTransportTest : WebSocketTransportTest(ClientCIO, ServerCIO) { - //on native we need more time here - override val testTimeout: Duration = 5.minutes - - //tests are ignored, because current CIO:native websockets implementation is unstable when working with large frames - @Test - @IgnoreNative - override fun largePayloadFireAndForget10() = super.largePayloadFireAndForget10() - - @Test - @IgnoreNative - override fun largePayloadMetadataPush10() = super.largePayloadMetadataPush10() - - @Test - @IgnoreNative - override fun largePayloadRequestChannel200() = super.largePayloadRequestChannel200() - - @Test - @IgnoreNative - override fun largePayloadRequestResponse100() = super.largePayloadRequestResponse100() -} +class CIOWebSocketTransportTest : WebSocketTransportTest(ClientCIO, ServerCIO) diff --git a/rsocket-transports/ktor-websocket-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketTransportTest.kt b/rsocket-transports/ktor-websocket-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketTransportTest.kt index d47c9a7d..ffd26b12 100644 --- a/rsocket-transports/ktor-websocket-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketTransportTest.kt +++ b/rsocket-transports/ktor-websocket-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketTransportTest.kt @@ -26,12 +26,12 @@ abstract class WebSocketTransportTest( private val serverEngine: ApplicationEngineFactory<*, *>, ) : TransportTest() { override suspend fun before() { - val port = PortProvider.next() - startServer( - WebSocketServerTransport(serverEngine, port = port) + val engine = startServer( + WebSocketServerTransport(serverEngine, port = 0) ) + val connector = engine.resolvedConnectors().single() client = connectClient( - WebSocketClientTransport(clientEngine, port = port, context = testContext) + WebSocketClientTransport(clientEngine, port = connector.port, context = testContext) ) } }