From 3a65201f73e39bc76f884eae8e74b1fb9d3f5527 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Thu, 17 Nov 2022 07:33:03 +0400 Subject: [PATCH] problem: timeout on unit tests (cherry picked from commit 255a3833fd587b8dca5b644f7b22fb6e8ddb50cc) --- .../emeraldpay/dshackle/upstream/ethereum/WsConnection.kt | 3 ++- .../dshackle/upstream/ethereum/WsConnectionSpec.groovy | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt index c30f3f89..5373e796 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt @@ -405,7 +405,8 @@ open class WsConnection( ) val response = Flux.from(rpcReceive.asFlux()) - .doOnSubscribe { sendRpc(request) } + // send the request _after_ WS subscribes to the responses, otherwise the response may come before the actual subscription and be lost + .doOnRequest { sendRpc(request) } .filter { resp -> resp.id.asNumber() == expectedId } .take(Defaults.timeout) .take(1) diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionSpec.groovy index 18350845..54849052 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionSpec.groovy @@ -92,7 +92,7 @@ class WsConnectionSpec extends Specification { it.id.asNumber() == 15L && Global.objectMapper.readValue(it.result, TransactionJson) == tx } .expectComplete() - .verify(Duration.ofSeconds(5)) + .verify(Duration.ofSeconds(1)) } def "Makes a RPC call - return null"() { @@ -115,7 +115,7 @@ class WsConnectionSpec extends Specification { it.resultAsRawString == 'null' } .expectComplete() - .verify(Duration.ofSeconds(5)) + .verify(Duration.ofSeconds(1)) } def "Makes a RPC call - return error"() { @@ -140,6 +140,6 @@ class WsConnectionSpec extends Specification { it.error.code == RpcResponseError.CODE_METHOD_NOT_EXIST && it.error.message == "test" } .expectComplete() - .verify(Duration.ofSeconds(5)) + .verify(Duration.ofSeconds(1)) } }