-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Error on invalid capability acquire/release request (#8133)
`capability/acquire` with an invalid method `executionContext/canModify` would previously timeout because the capability router simply didn't support that kind of capability request. Now rather than timing out, indicating a failure on LS, we report an error. Closes #8038.
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...guage-server/src/test/scala/org/enso/languageserver/websocket/json/CapabilitiesTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.enso.languageserver.websocket.json | ||
|
||
import io.circe.literal._ | ||
import io.circe.parser.parse | ||
import io.circe.syntax.EncoderOps | ||
import org.enso.polyglot.runtime.Runtime.Api | ||
|
||
import java.util.UUID | ||
|
||
class CapabilitiesTest extends BaseServerTest { | ||
|
||
"capability/acquire" must { | ||
|
||
"return an error response to the client when requesting it for `executionContext/canModify`" in { | ||
val client = getInitialisedWsClient() | ||
val contextId = createExecutionContext(client) | ||
client.send(json""" | ||
{ "jsonrpc": "2.0", | ||
"method": "capability/acquire", | ||
"id": 1, | ||
"params": { | ||
"method" : "executionContext/canModify", | ||
"registerOptions": { | ||
"contextId" : $contextId | ||
} | ||
} | ||
} | ||
""") | ||
val response = parse(client.expectMessage()).rightValue.asObject.value | ||
response("jsonrpc") shouldEqual Some("2.0".asJson) | ||
response("id") shouldEqual Some(1.asJson) | ||
val err = response("error").value.asObject.value | ||
err("message") shouldEqual Some("Service error".asJson) | ||
} | ||
} | ||
|
||
"capability/release" must { | ||
|
||
"return an error response to the client when requesting it for `executionContext/canModify`" in { | ||
val client = getInitialisedWsClient() | ||
val contextId = createExecutionContext(client) | ||
client.send(json""" | ||
{ "jsonrpc": "2.0", | ||
"method": "capability/release", | ||
"id": 1, | ||
"params": { | ||
"method" : "executionContext/canModify", | ||
"registerOptions": { | ||
"contextId" : $contextId | ||
} | ||
} | ||
} | ||
""") | ||
val response = parse(client.expectMessage()).rightValue.asObject.value | ||
response("jsonrpc") shouldEqual Some("2.0".asJson) | ||
response("id") shouldEqual Some(1.asJson) | ||
val err = response("error").value.asObject.value | ||
err("message") shouldEqual Some("Service error".asJson) | ||
} | ||
} | ||
|
||
private def createExecutionContext(client: WsTestClient): UUID = { | ||
client.send(ExecutionContextJsonMessages.executionContextCreateRequest(0)) | ||
val (requestId, contextId) = | ||
runtimeConnectorProbe.receiveN(1).head match { | ||
case Api.Request(requestId, Api.CreateContextRequest(contextId)) => | ||
(requestId, contextId) | ||
case msg => | ||
fail(s"Unexpected message: $msg") | ||
} | ||
|
||
runtimeConnectorProbe.lastSender ! Api.Response( | ||
requestId, | ||
Api.CreateContextResponse(contextId) | ||
) | ||
client.expectJson( | ||
ExecutionContextJsonMessages.executionContextCreateResponse(0, contextId) | ||
) | ||
contextId | ||
} | ||
} |