problem: some nodes may respond with a JSON RPC setting a non-200 status code but Dshackle ignores that JSON

This commit is contained in:
a10zn8
2022-09-29 04:26:20 +04:00
parent 5df10706dd
commit ddc6fb2a4c
2 changed files with 112 additions and 33 deletions

View File

@@ -26,6 +26,7 @@ import org.mockserver.model.HttpRequest
import org.mockserver.model.HttpResponse
import org.mockserver.model.MediaType
import org.springframework.util.SocketUtils
import reactor.core.Exceptions
import reactor.test.StepVerifier
import spock.lang.Specification
@@ -84,7 +85,7 @@ class JsonRpcHttpClientSpec extends Specification {
.withBody("pong")
)
when:
def act = client.execute("ping".bytes).map { new String(it) }
def act = client.execute("ping".bytes).map { new String(it.t2) }
then:
StepVerifier.create(act)
.expectNext("pong")
@@ -111,13 +112,44 @@ class JsonRpcHttpClientSpec extends Specification {
.withBody("pong")
)
when:
def act = client.execute("ping".bytes).map { new String(it) }
def act = client.read(
new JsonRpcRequest("ping", [])
).block(Duration.ofSeconds(1))
then:
StepVerifier.create(act)
.expectErrorMatches { t ->
t instanceof JsonRpcException && t.error.code == RpcResponseError.CODE_UPSTREAM_INVALID_RESPONSE
}
.verify(Duration.ofSeconds(1))
def t = thrown(RuntimeException) // reactor.core.Exceptions$ReactiveException
t.cause instanceof JsonRpcException
with(((JsonRpcException)t.cause).error) {
code == RpcResponseError.CODE_UPSTREAM_INVALID_RESPONSE
message == "HTTP Code: 500"
}
}
def "Tries to extract message if HTTP error if it still contains a JSON RPC message"() {
setup:
def client = new JsonRpcHttpClient("localhost:${port}", metrics, null, null)
mockServer.when(
HttpRequest.request()
).respond(
HttpResponse.response()
.withStatusCode(500)
.withBody('{' +
'"jsonrpc": "2.0", ' +
'"id": 1, ' +
'"error": {"code": -32603, "message": "Something happened"}' +
'}')
)
when:
def act = client.read(
new JsonRpcRequest("ping", [])
).block(Duration.ofSeconds(1))
then:
def t = thrown(RuntimeException) // reactor.core.Exceptions$ReactiveException
t.cause instanceof JsonRpcException
with(((JsonRpcException)t.cause).error) {
code == -32603
message == "Something happened"
}
}
}