Streamable HTTP transport tests follow-up (#559)
<!-- Provide a brief summary of your changes --> ## Motivation and Context <!-- Why is this change needed? What problem does it solve? --> Replace `withTimeout` with `eventually` in test assertions and improve readability in exception handling ## How Has This Been Tested? <!-- Have you tested this in a real application? Which scenarios were tested? --> ## Breaking Changes <!-- Will users need to update their code or configurations? --> None ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [x] Test update ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [x] My code follows the repository's style guidelines - [x] New and existing tests pass locally - [ ] I have added appropriate error handling - [ ] I have added or updated documentation as needed ## Additional context <!-- Add any other context, implementation notes, or design decisions -->
This commit is contained in:
parent
fe97b442f6
commit
947d03dd44
1 changed files with 11 additions and 11 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package io.modelcontextprotocol.kotlin.sdk.client.streamable.http
|
package io.modelcontextprotocol.kotlin.sdk.client.streamable.http
|
||||||
|
|
||||||
import io.kotest.assertions.withClue
|
import io.kotest.assertions.fail
|
||||||
|
import io.kotest.assertions.nondeterministic.eventually
|
||||||
import io.kotest.matchers.collections.shouldHaveSize
|
import io.kotest.matchers.collections.shouldHaveSize
|
||||||
import io.kotest.matchers.shouldBe
|
import io.kotest.matchers.shouldBe
|
||||||
import io.kotest.matchers.types.shouldBeInstanceOf
|
import io.kotest.matchers.types.shouldBeInstanceOf
|
||||||
|
|
@ -122,8 +123,8 @@ class StreamableHttpClientTransportTest {
|
||||||
transport.close()
|
transport.close()
|
||||||
try {
|
try {
|
||||||
transport.close()
|
transport.close()
|
||||||
} catch (e: Exception) {
|
} catch (_: Exception) {
|
||||||
withClue("We expect no exceptions when closing already closed transport") { e shouldBe null }
|
fail("We expect no exceptions when closing already closed transport")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -323,10 +324,9 @@ class StreamableHttpClientTransportTest {
|
||||||
assertTrue(sseStarted, "SSE should start after initialized notification")
|
assertTrue(sseStarted, "SSE should start after initialized notification")
|
||||||
|
|
||||||
// Test 2: Verify received notifications
|
// Test 2: Verify received notifications
|
||||||
assertEquals(3, receivedMessages.size)
|
receivedMessages shouldHaveSize 3
|
||||||
assertTrue(receivedMessages.all { it is JSONRPCNotification })
|
|
||||||
|
|
||||||
val notifications = receivedMessages.filterIsInstance<JSONRPCNotification>()
|
val notifications = receivedMessages.filterIsInstance<JSONRPCNotification>()
|
||||||
|
notifications shouldHaveSize 3
|
||||||
|
|
||||||
// Verify progress notification
|
// Verify progress notification
|
||||||
val progressNotif = notifications[0]
|
val progressNotif = notifications[0]
|
||||||
|
|
@ -531,11 +531,11 @@ class StreamableHttpClientTransportTest {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
withTimeout(2.seconds) {
|
eventually {
|
||||||
twoMessagesReceived.await()
|
twoMessagesReceived.await()
|
||||||
}
|
}
|
||||||
|
|
||||||
receivedMessages.size shouldBe 2
|
receivedMessages shouldHaveSize 2
|
||||||
|
|
||||||
val firstNotification = receivedMessages[0] as JSONRPCNotification
|
val firstNotification = receivedMessages[0] as JSONRPCNotification
|
||||||
firstNotification.method shouldBe "notifications/progress"
|
firstNotification.method shouldBe "notifications/progress"
|
||||||
|
|
@ -590,7 +590,7 @@ class StreamableHttpClientTransportTest {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val error = withTimeout(2.seconds) { errorDeferred.await() }
|
val error = eventually { errorDeferred.await() }
|
||||||
|
|
||||||
receivedErrors.size shouldBe 1
|
receivedErrors.size shouldBe 1
|
||||||
error.message shouldBe "Streamable HTTP error: $errorMessage"
|
error.message shouldBe "Streamable HTTP error: $errorMessage"
|
||||||
|
|
@ -640,7 +640,7 @@ class StreamableHttpClientTransportTest {
|
||||||
|
|
||||||
val (receivedMessages, receivedErrors) = setupTransportAndCollectMessages(transport)
|
val (receivedMessages, receivedErrors) = setupTransportAndCollectMessages(transport)
|
||||||
|
|
||||||
withTimeout(2.seconds) {
|
eventually {
|
||||||
while (receivedMessages.isEmpty()) {
|
while (receivedMessages.isEmpty()) {
|
||||||
delay(10)
|
delay(10)
|
||||||
}
|
}
|
||||||
|
|
@ -648,7 +648,7 @@ class StreamableHttpClientTransportTest {
|
||||||
|
|
||||||
transport.close()
|
transport.close()
|
||||||
|
|
||||||
assertTrue(receivedMessages.isNotEmpty())
|
receivedMessages shouldHaveSize 3
|
||||||
|
|
||||||
receivedMessages.forEach { message ->
|
receivedMessages.forEach { message ->
|
||||||
message.shouldBeInstanceOf<JSONRPCNotification>()
|
message.shouldBeInstanceOf<JSONRPCNotification>()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue