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:
Anastasiia Zarechneva 2026-02-23 14:03:39 +01:00 • committed by GitHub
commit 947d03dd44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
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.shouldBe
import io.kotest.matchers.types.shouldBeInstanceOf
@ -122,8 +123,8 @@ class StreamableHttpClientTransportTest {
transport.close()
try {
transport.close()
} catch (e: Exception) {
withClue("We expect no exceptions when closing already closed transport") { e shouldBe null }
} catch (_: Exception) {
fail("We expect no exceptions when closing already closed transport")
}
}
@ -323,10 +324,9 @@ class StreamableHttpClientTransportTest {
assertTrue(sseStarted, "SSE should start after initialized notification")
// Test 2: Verify received notifications
assertEquals(3, receivedMessages.size)
assertTrue(receivedMessages.all { it is JSONRPCNotification })
receivedMessages shouldHaveSize 3
val notifications = receivedMessages.filterIsInstance<JSONRPCNotification>()
notifications shouldHaveSize 3
// Verify progress notification
val progressNotif = notifications[0]
@ -531,11 +531,11 @@ class StreamableHttpClientTransportTest {
),
)
withTimeout(2.seconds) {
eventually {
twoMessagesReceived.await()
}
receivedMessages.size shouldBe 2
receivedMessages shouldHaveSize 2
val firstNotification = receivedMessages[0] as JSONRPCNotification
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
error.message shouldBe "Streamable HTTP error: $errorMessage"
@ -640,7 +640,7 @@ class StreamableHttpClientTransportTest {
val (receivedMessages, receivedErrors) = setupTransportAndCollectMessages(transport)
withTimeout(2.seconds) {
eventually {
while (receivedMessages.isEmpty()) {
delay(10)
}
@ -648,7 +648,7 @@ class StreamableHttpClientTransportTest {
transport.close()
assertTrue(receivedMessages.isNotEmpty())
receivedMessages shouldHaveSize 3
receivedMessages.forEach { message ->
message.shouldBeInstanceOf<JSONRPCNotification>()