Skip to content

Commit 239fc97

Browse files
tiginamariadevcrocod
authored andcommitted
Fix tests
1 parent 472d368 commit 239fc97

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/WebSocketIntegrationTest.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class WebSocketIntegrationTest {
4242
withContext(Dispatchers.Default) {
4343
withTimeout(1000) {
4444
server = initServer()
45-
client = initClient()
45+
val port = server.engine.resolvedConnectors().first().port
46+
client = initClient(serverPort = port)
4647
}
4748
}
4849
} finally {
@@ -67,7 +68,8 @@ class WebSocketIntegrationTest {
6768
withContext(Dispatchers.Default) {
6869
withTimeout(1000) {
6970
server = initServer()
70-
client = initClient()
71+
val port = server.engine.resolvedConnectors().first().port
72+
client = initClient("Client A", port)
7173

7274
val promptA = getPrompt(client, "Client A")
7375
assertTrue { "Client A" in promptA }
@@ -97,8 +99,9 @@ class WebSocketIntegrationTest {
9799
withContext(Dispatchers.Default) {
98100
withTimeout(1000) {
99101
server = initServer()
100-
clientA = initClient()
101-
clientB = initClient()
102+
val port = server.engine.resolvedConnectors().first().port
103+
clientA = initClient("Client A", port)
104+
clientB = initClient("Client B",port)
102105

103106
// Step 3: Send a prompt request from Client A
104107
val promptA = getPrompt(clientA, "Client A")
@@ -116,7 +119,7 @@ class WebSocketIntegrationTest {
116119
}
117120
}
118121

119-
private suspend fun initClient(name: String = ""): Client {
122+
private suspend fun initClient(name: String = "", serverPort: Int): Client {
120123
val client = Client(
121124
Implementation(name = name, version = "1.0.0"),
122125
)
@@ -129,7 +132,7 @@ class WebSocketIntegrationTest {
129132
val transport = httpClient.mcpWebSocketTransport {
130133
url {
131134
host = URL
132-
port = PORT
135+
port = serverPort
133136
}
134137
}
135138

@@ -193,12 +196,12 @@ class WebSocketIntegrationTest {
193196
),
194197
)
195198

196-
return (response?.messages?.first()?.content as? TextContent)?.text
199+
return (response.messages.first().content as? TextContent)?.text
197200
?: error("Failed to receive prompt for Client $clientName")
198201
}
199202

200203
companion object {
201-
private const val PORT = 3002
202-
private const val URL = "localhost"
204+
private const val PORT = 0
205+
private const val URL = "127.0.0.1"
203206
}
204207
}

0 commit comments

Comments
 (0)