Skip to content

Commit 1744e16

Browse files
authored
Fix flaky StdioClientTransportErrorHandlingTest (#457)
## Changes Fix flaky StdioClientTransportErrorHandlingTest Use non-empty buffer for reliability ## How Has This Been Tested? Unit test ## Breaking Changes <!-- Will users need to update their code or configurations? --> ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] 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 ## 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 -->
1 parent 64f2d18 commit 1744e16

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/stdio/StdioClientTransportErrorHandlingTest.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ class StdioClientTransportErrorHandlingTest {
4141
val stderrBuffer = Buffer()
4242
// Empty stderr = immediate EOF
4343

44-
val inputBuffer = Buffer()
45-
inputBuffer.writeString("""data: {"jsonrpc":"2.0","method":"ping","id":1}\n\n""")
44+
val inputBuffer = createNonEmptyBuffer {
45+
"""data: {"jsonrpc":"2.0","method":"ping","id":1}\n\n"""
46+
}
4647
val outputBuffer = Buffer()
4748

4849
transport = StdioClientTransport(
@@ -66,8 +67,9 @@ class StdioClientTransportErrorHandlingTest {
6667

6768
@Test
6869
fun `should call onClose exactly once on error scenarios`() = runTest {
69-
val stderrBuffer = Buffer()
70-
stderrBuffer.write("FATAL: critical error\n".encodeToByteArray())
70+
val stderrBuffer = createNonEmptyBuffer {
71+
"FATAL: critical error\n"
72+
}
7173

7274
val inputBuffer = Buffer()
7375
val outputBuffer = Buffer()
@@ -149,8 +151,9 @@ class StdioClientTransportErrorHandlingTest {
149151
fun `Send should handle exceptions`(throwable: Throwable, shouldWrap: Boolean, expectedCode: Int?) = runTest {
150152
val sendChannel: Channel<JSONRPCMessage> = mockk(relaxed = true)
151153

154+
val stdin = createNonEmptyBuffer { "id: 1\ndata:\n" }
152155
transport = StdioClientTransport(
153-
input = Buffer(),
156+
input = stdin,
154157
output = Buffer(),
155158
sendChannel = sendChannel,
156159
)
@@ -173,4 +176,10 @@ class StdioClientTransportErrorHandlingTest {
173176
exception shouldBeSameInstanceAs throwable
174177
}
175178
}
179+
180+
fun createNonEmptyBuffer(block: () -> String): Buffer {
181+
val buffer = Buffer()
182+
buffer.writeString(block())
183+
return buffer
184+
}
176185
}

0 commit comments

Comments
 (0)