problem: no response for requests that produce very large results which causes the upstream to break the WS connection
This commit is contained in:
@@ -93,6 +93,20 @@ class WsConnectionRealSpec extends Specification {
|
||||
act[0].value.contains("\"params\":[\"newHeads\"]")
|
||||
}
|
||||
|
||||
def "Error on request when server disconnects"() {
|
||||
when:
|
||||
conn.connect()
|
||||
conn.reconnectIntervalSeconds = 2
|
||||
|
||||
def resp = conn.call(new JsonRpcRequest("foo_bar", []))
|
||||
|
||||
then:
|
||||
StepVerifier.create(resp)
|
||||
.then { server.stop() }
|
||||
.expectError()
|
||||
.verify(Duration.ofSeconds(1))
|
||||
}
|
||||
|
||||
def "Gets UNAVAIL status right after disconnect"() {
|
||||
setup:
|
||||
def up = Mock(DefaultUpstream)
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package io.emeraldpay.dshackle.upstream.rpcclient
|
||||
|
||||
import io.emeraldpay.dshackle.reader.Reader
|
||||
import reactor.core.publisher.Mono
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.time.Duration
|
||||
|
||||
class JsonRpcSwitchClientSpec extends Specification {
|
||||
|
||||
def "Uses primary response if it works"() {
|
||||
setup:
|
||||
def primaryCalled = false
|
||||
def secondaryCalled = false
|
||||
def request = new JsonRpcRequest("eth_test", [])
|
||||
def response = JsonRpcResponse.ok("test".bytes, new JsonRpcResponse.NumberId(100))
|
||||
def primary = Mock(Reader<JsonRpcRequest, JsonRpcResponse>) {
|
||||
1 * read(request) >> Mono.fromCallable {
|
||||
primaryCalled = true
|
||||
response
|
||||
}
|
||||
}
|
||||
def secondary = Mock(Reader<JsonRpcRequest, JsonRpcResponse>) {
|
||||
_ * read(request) >> Mono.fromCallable {
|
||||
secondaryCalled = true
|
||||
response
|
||||
}
|
||||
}
|
||||
|
||||
def client = new JsonRpcSwitchClient(primary, secondary)
|
||||
|
||||
when:
|
||||
def act = client.read(request).block(Duration.ofSeconds(1))
|
||||
|
||||
then:
|
||||
act == response
|
||||
primaryCalled
|
||||
!secondaryCalled
|
||||
}
|
||||
|
||||
def "Uses secondary response if primary fails"() {
|
||||
setup:
|
||||
def primaryCalled = false
|
||||
def secondaryCalled = false
|
||||
def request = new JsonRpcRequest("eth_test", [])
|
||||
def response = JsonRpcResponse.ok("test".bytes, new JsonRpcResponse.NumberId(100))
|
||||
def primary = Mock(Reader<JsonRpcRequest, JsonRpcResponse>) {
|
||||
1 * read(request) >> Mono.fromCallable {
|
||||
primaryCalled = true
|
||||
throw new IllegalStateException("Primary Fail")
|
||||
}
|
||||
}
|
||||
def secondary = Mock(Reader<JsonRpcRequest, JsonRpcResponse>) {
|
||||
1 * read(request) >> Mono.fromCallable {
|
||||
secondaryCalled = true
|
||||
response
|
||||
}
|
||||
}
|
||||
|
||||
def client = new JsonRpcSwitchClient(primary, secondary)
|
||||
|
||||
when:
|
||||
def act = client.read(request).block(Duration.ofSeconds(1))
|
||||
|
||||
then:
|
||||
act == response
|
||||
primaryCalled
|
||||
secondaryCalled
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.emeraldpay.dshackle.upstream.rpcclient
|
||||
|
||||
import io.emeraldpay.dshackle.upstream.ethereum.WsConnection
|
||||
import reactor.core.Exceptions
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.time.Duration
|
||||
|
||||
class JsonRpcWsClientSpec extends Specification {
|
||||
|
||||
def "Produce error if WS is not connected"() {
|
||||
setup:
|
||||
def ws = Mock(WsConnection)
|
||||
def client = new JsonRpcWsClient(ws)
|
||||
when:
|
||||
client.read(new JsonRpcRequest("foo_bar", [], 1))
|
||||
.block(Duration.ofSeconds(1))
|
||||
then:
|
||||
def t = thrown(Exceptions.ReactiveException)
|
||||
t.cause instanceof JsonRpcException
|
||||
1 * ws.isConnected() >> false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user