Skip to content

Commit

Permalink
fix address reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
whyoleg committed Apr 11, 2024
1 parent 854ebe8 commit a06194e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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) {
Expand All @@ -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()
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -50,7 +51,7 @@ class TcpServerTest : SuspendTest, TestWithLeakCheck {
payload(text)
}
}
}.connect(clientTransport)
}.connect(clientTransport(server))

val client1 = newClient("ok")
client1.requestResponse(payload("ok")).close()
Expand Down Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
}

0 comments on commit a06194e

Please sign in to comment.