-
Notifications
You must be signed in to change notification settings - Fork 176
Fix: Handle logging/setLevel request for server #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -886,6 +886,86 @@ class ClientTest { | |
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `should handle logging setLevel request`() = runTest { | ||
| val server = Server( | ||
| Implementation(name = "test server", version = "1.0"), | ||
| ServerOptions( | ||
| capabilities = ServerCapabilities( | ||
| logging = EmptyJsonObject, | ||
| ), | ||
| ), | ||
| ) | ||
|
|
||
| val client = Client( | ||
| clientInfo = Implementation(name = "test client", version = "1.0"), | ||
| options = ClientOptions( | ||
| capabilities = ClientCapabilities(), | ||
| ), | ||
| ) | ||
|
|
||
| val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() | ||
|
|
||
| val receivedMessages = mutableListOf<LoggingMessageNotification>() | ||
| client.setNotificationHandler<LoggingMessageNotification>(Method.Defined.NotificationsMessage) { notification -> | ||
| receivedMessages.add(notification) | ||
| CompletableDeferred(Unit) | ||
| } | ||
|
|
||
| val serverSessionResult = CompletableDeferred<ServerSession>() | ||
|
|
||
| listOf( | ||
| launch { | ||
| client.connect(clientTransport) | ||
| println("Client connected") | ||
| }, | ||
| launch { | ||
| serverSessionResult.complete(server.connect(serverTransport)) | ||
| println("Server connected") | ||
| }, | ||
| ).joinAll() | ||
|
|
||
| val serverSession = serverSessionResult.await() | ||
|
|
||
| // Set logging level to warning | ||
| val minLevel = LoggingLevel.warning | ||
| val result = client.setLoggingLevel(minLevel) | ||
| assertEquals(EmptyJsonObject, result._meta) | ||
|
|
||
| // Send messages of different levels | ||
| val testMessages = listOf( | ||
| LoggingLevel.debug to "Debug - should be filtered", | ||
| LoggingLevel.info to "Info - should be filtered", | ||
| LoggingLevel.warning to "Warning - should pass", | ||
| LoggingLevel.error to "Error - should pass", | ||
| ) | ||
|
|
||
| testMessages.forEach { (level, message) -> | ||
| serverSession.sendLoggingMessage( | ||
| LoggingMessageNotification( | ||
| params = LoggingMessageNotification.Params( | ||
| level = level, | ||
| data = buildJsonObject { put("message", message) }, | ||
| ), | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| delay(100) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. awaitility is more correct than delay
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // Only warning and error should be received | ||
| assertEquals(2, receivedMessages.size, "Should receive only 2 messages (warning and error)") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't awaitility be used here? It will be needed for sure to verify rate-limiting
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's common code, I used |
||
|
|
||
| // Verify all received messages have severity >= minLevel | ||
| receivedMessages.forEach { message -> | ||
| val messageSeverity = message.params.level.ordinal | ||
| assertTrue( | ||
| messageSeverity >= minLevel.ordinal, | ||
| "Received message with level ${message.params.level} should have severity >= $minLevel", | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `should handle server elicitation`() = runTest { | ||
| val client = Client( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.