Skip to content

Commit 6735788

Browse files
committed
test(streamable-http): make pagination tests deterministic and simplify assertions; use LoggingLevel.entries
1 parent e6812ac commit 6735788

4 files changed

Lines changed: 44 additions & 38 deletions

File tree

integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/AbstractPromptIntegrationTest.kt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -723,16 +723,16 @@ abstract class AbstractPromptIntegrationTest : KotlinTestBase() {
723723
}
724724
}
725725

726-
val first = client.listPrompts()
727-
assertTrue(first.prompts.isNotEmpty())
728-
val nextCursor = first.nextCursor
729-
assertNotNull(nextCursor)
730-
731-
val second = client.listPrompts(ListPromptsRequest(PaginatedRequestParams(cursor = nextCursor)))
732-
assertTrue(second.prompts.isNotEmpty())
733-
734-
val combined = first.prompts + second.prompts
735-
assertTrue(combined.any { it.name.startsWith(pagePrefix) })
726+
val allPrompts = mutableListOf<io.modelcontextprotocol.kotlin.sdk.types.Prompt>()
727+
var currentCursor: String? = null
728+
do {
729+
val request = if (currentCursor == null) ListPromptsRequest() else ListPromptsRequest(PaginatedRequestParams(cursor = currentCursor))
730+
val response = client.listPrompts(request)
731+
allPrompts.addAll(response.prompts)
732+
currentCursor = response.nextCursor
733+
} while (currentCursor != null)
734+
735+
assertTrue(allPrompts.any { it.name.startsWith(pagePrefix) })
736736
}
737737

738738
@Test
@@ -746,10 +746,8 @@ abstract class AbstractPromptIntegrationTest : KotlinTestBase() {
746746
}
747747
}
748748

749-
val exception = org.junit.jupiter.api.assertThrows<McpException> {
750-
runBlocking {
751-
client.listPrompts(ListPromptsRequest(PaginatedRequestParams(cursor = "not-a-number")))
752-
}
749+
val exception = kotlin.test.assertFailsWith<McpException> {
750+
client.listPrompts(ListPromptsRequest(PaginatedRequestParams(cursor = "not-a-number")))
753751
}
754752

755753
kotlin.test.assertEquals(RPCError.ErrorCode.INTERNAL_ERROR, exception.code)

integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/AbstractResourceIntegrationTest.kt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,21 @@ abstract class AbstractResourceIntegrationTest : KotlinTestBase() {
335335
}
336336
}
337337

338-
val first = client.listResources()
339-
assertTrue(first.resources.isNotEmpty())
340-
val next = first.nextCursor
341-
assertNotNull(next)
338+
val combinedUris = mutableListOf<String>()
339+
var currentCursor: String? = null
340+
341+
do {
342+
val request = if (currentCursor == null) {
343+
ListResourcesRequest()
344+
} else {
345+
ListResourcesRequest(PaginatedRequestParams(cursor = currentCursor))
346+
}
342347

343-
val second = client.listResources(ListResourcesRequest(PaginatedRequestParams(cursor = next)))
344-
assertTrue(second.resources.isNotEmpty())
348+
val response = client.listResources(request)
349+
combinedUris += response.resources.map { it.uri }
350+
currentCursor = response.nextCursor
351+
} while (currentCursor != null)
345352

346-
val combinedUris = (first.resources + second.resources).map { it.uri }
347353
assertTrue(combinedUris.any { it.contains(prefix) })
348354
}
349355

@@ -358,10 +364,8 @@ abstract class AbstractResourceIntegrationTest : KotlinTestBase() {
358364
}
359365
}
360366

361-
val exception = org.junit.jupiter.api.assertThrows<McpException> {
362-
runBlocking {
363-
client.listResources(ListResourcesRequest(PaginatedRequestParams(cursor = "bad")))
364-
}
367+
val exception = kotlin.test.assertFailsWith<McpException> {
368+
client.listResources(ListResourcesRequest(PaginatedRequestParams(cursor = "bad")))
365369
}
366370

367371
kotlin.test.assertEquals(RPCError.ErrorCode.INTERNAL_ERROR, exception.code)

integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/AbstractToolIntegrationTest.kt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -817,15 +817,21 @@ abstract class AbstractToolIntegrationTest : KotlinTestBase() {
817817
}
818818
}
819819

820-
val first = client.listTools()
821-
assertTrue(first.tools.isNotEmpty())
822-
val next = first.nextCursor
823-
assertNotNull(next)
820+
val combinedNames = mutableListOf<String>()
821+
var currentCursor: String? = null
824822

825-
val second = client.listTools(ListToolsRequest(PaginatedRequestParams(cursor = next)))
826-
assertTrue(second.tools.isNotEmpty())
823+
do {
824+
val request = if (currentCursor == null) {
825+
ListToolsRequest()
826+
} else {
827+
ListToolsRequest(PaginatedRequestParams(cursor = currentCursor))
828+
}
829+
830+
val response = client.listTools(request)
831+
combinedNames += response.tools.map { it.name }
832+
currentCursor = response.nextCursor
833+
} while (currentCursor != null)
827834

828-
val combinedNames = (first.tools + second.tools).map { it.name }
829835
assertTrue(combinedNames.any { it.startsWith(prefix) })
830836
}
831837

@@ -840,10 +846,8 @@ abstract class AbstractToolIntegrationTest : KotlinTestBase() {
840846
}
841847
}
842848

843-
val exception = org.junit.jupiter.api.assertThrows<io.modelcontextprotocol.kotlin.sdk.types.McpException> {
844-
runBlocking {
845-
client.listTools(ListToolsRequest(PaginatedRequestParams(cursor = "bad")))
846-
}
849+
val exception = kotlin.test.assertFailsWith<io.modelcontextprotocol.kotlin.sdk.types.McpException> {
850+
client.listTools(ListToolsRequest(PaginatedRequestParams(cursor = "bad")))
847851
}
848852

849853
kotlin.test.assertEquals(io.modelcontextprotocol.kotlin.sdk.types.RPCError.ErrorCode.INTERNAL_ERROR, exception.code)

integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/streamablehttp/LoggingIntegrationTestStreamableHttp.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class LoggingIntegrationTestStreamableHttp : KotlinTestBase() {
5151
}
5252

5353
server.addTool(name = "test-logging-level", description = "test") { request ->
54-
LoggingLevel.values().forEach { level ->
54+
LoggingLevel.entries.forEach { level ->
5555
sendLoggingMessage(
5656
LoggingMessageNotification(
5757
LoggingMessageNotificationParams(
@@ -105,7 +105,7 @@ class LoggingIntegrationTestStreamableHttp : KotlinTestBase() {
105105

106106
client.callTool(CallToolRequest(CallToolRequestParams("test-logging-level")))
107107

108-
val expectedLevels = LoggingLevel.values().filter { it >= LoggingLevel.Warning }
108+
val expectedLevels = LoggingLevel.entries.filter { it >= LoggingLevel.Warning }
109109
// wait for expected notifications to arrive (transport may deliver asynchronously)
110110
withTimeout(2000) {
111111
while (receivedMessages.size < expectedLevels.size) {

0 commit comments

Comments
 (0)