mirror of
https://github.com/enso-org/enso.git
synced 2024-11-22 22:10:15 +03:00
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.
This commit is contained in:
parent
c1259cb4d2
commit
61a0c8ce3f
@ -4,6 +4,8 @@ import akka.actor.{Actor, ActorRef, Props}
|
||||
import com.typesafe.scalalogging.LazyLogging
|
||||
import org.enso.languageserver.capability.CapabilityProtocol.{
|
||||
AcquireCapability,
|
||||
CapabilityAcquisitionBadRequest,
|
||||
CapabilityReleaseBadRequest,
|
||||
ReleaseCapability
|
||||
}
|
||||
import org.enso.languageserver.data.{
|
||||
@ -65,6 +67,10 @@ class CapabilityRouter(
|
||||
CapabilityRegistration(ReceivesSuggestionsDatabaseUpdates())
|
||||
) =>
|
||||
suggestionsHandler.forward(msg)
|
||||
case AcquireCapability(_, _) =>
|
||||
sender() ! CapabilityAcquisitionBadRequest
|
||||
case ReleaseCapability(_, _) =>
|
||||
sender() ! CapabilityReleaseBadRequest
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user