Fix logs and test (#556)

This commit is contained in:
KirillPamPam
2024-08-27 15:08:32 +04:00
committed by GitHub
parent 8ac58f58b7
commit 4943953c42
2 changed files with 21 additions and 18 deletions

View File

@@ -187,7 +187,7 @@ class ChainIdValidator(
} }
} }
.onErrorResume { .onErrorResume {
log.error("Error during chain validation", it) log.error("Error during chain validation of upstream {}, reason - {}", upstream.getId(), it.message)
Mono.just(onError) Mono.just(onError)
} }
} }
@@ -197,11 +197,13 @@ class ChainIdValidator(
.read(ChainRequest("eth_chainId", ListParams())) .read(ChainRequest("eth_chainId", ListParams()))
.retryRandomBackoff(3, Duration.ofMillis(100), Duration.ofMillis(500)) { ctx -> .retryRandomBackoff(3, Duration.ofMillis(100), Duration.ofMillis(500)) { ctx ->
log.warn( log.warn(
"error during chainId retrieving for ${upstream.getId()}, iteration ${ctx.iteration()}, " + "error during chainId retrieving for {}, iteration {}, reason - {}",
"message ${ctx.exception().message}", upstream.getId(),
ctx.iteration(),
ctx.exception().message,
) )
} }
.doOnError { log.error("Error during execution 'eth_chainId' - ${it.message} for ${upstream.getId()}") } .doOnError { log.error("Error during execution 'eth_chainId' - {} for {}", it.message, upstream.getId()) }
.flatMap(ChainResponse::requireStringResult) .flatMap(ChainResponse::requireStringResult)
} }
@@ -210,11 +212,13 @@ class ChainIdValidator(
.read(ChainRequest("net_version", ListParams())) .read(ChainRequest("net_version", ListParams()))
.retryRandomBackoff(3, Duration.ofMillis(100), Duration.ofMillis(500)) { ctx -> .retryRandomBackoff(3, Duration.ofMillis(100), Duration.ofMillis(500)) { ctx ->
log.warn( log.warn(
"error during netVersion retrieving for ${upstream.getId()}, iteration ${ctx.iteration()}, " + "error during netVersion retrieving for {}, iteration {}, reason - {}",
"message ${ctx.exception().message}", upstream.getId(),
ctx.iteration(),
ctx.exception().message,
) )
} }
.doOnError { log.error("Error during execution 'net_version' - ${it.message} for ${upstream.getId()}") } .doOnError { log.error("Error during execution 'net_version' - {} for {}", it.message, upstream.getId()) }
.flatMap(ChainResponse::requireStringResult) .flatMap(ChainResponse::requireStringResult)
} }
} }
@@ -237,8 +241,10 @@ class OldBlockValidator(
} }
.retryRandomBackoff(3, Duration.ofMillis(100), Duration.ofMillis(500)) { ctx -> .retryRandomBackoff(3, Duration.ofMillis(100), Duration.ofMillis(500)) { ctx ->
log.warn( log.warn(
"error during old block retrieving for ${upstream.getId()}, iteration ${ctx.iteration()}, " + "error during old block retrieving for {}, iteration {}, reason - {}",
"message ${ctx.exception().message}", upstream.getId(),
ctx.iteration(),
ctx.exception().message,
) )
} }
.map { result -> .map { result ->
@@ -251,7 +257,7 @@ class OldBlockValidator(
ValidateUpstreamSettingsResult.UPSTREAM_VALID ValidateUpstreamSettingsResult.UPSTREAM_VALID
} }
.onErrorResume { .onErrorResume {
log.warn("Error during old blocks validation", it) log.warn("Error during old blocks validation of upstream {}, reason - {}", upstream.getId(), it.message)
Mono.just(ValidateUpstreamSettingsResult.UPSTREAM_VALID) Mono.just(ValidateUpstreamSettingsResult.UPSTREAM_VALID)
} }
} }

View File

@@ -16,6 +16,7 @@ import io.emeraldpay.dshackle.upstream.ethereum.json.BlockJson
import io.emeraldpay.dshackle.upstream.ethereum.json.TransactionRefJson import io.emeraldpay.dshackle.upstream.ethereum.json.TransactionRefJson
import io.emeraldpay.dshackle.upstream.forkchoice.AlwaysForkChoice import io.emeraldpay.dshackle.upstream.forkchoice.AlwaysForkChoice
import io.emeraldpay.dshackle.upstream.rpcclient.ListParams import io.emeraldpay.dshackle.upstream.rpcclient.ListParams
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.kotlin.doReturn import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock import org.mockito.kotlin.mock
@@ -179,21 +180,17 @@ class GenericRpcHeadTest {
Duration.ofSeconds(5), Duration.ofSeconds(5),
) )
StepVerifier.withVirtualTime { head.getFlux() } StepVerifier.withVirtualTime { head.headLiveness() }
.expectSubscription() .expectSubscription()
.then { head.start() } .then { head.start() }
.expectNoEvent(Duration.ofSeconds(5)) .expectNoEvent(Duration.ofSeconds(5))
.expectNext(BlockContainer.from(block1))
.expectNoEvent(Duration.ofSeconds(5)) .expectNoEvent(Duration.ofSeconds(5))
.then { .expectNext(HeadLivenessState.FATAL_ERROR)
StepVerifier.create(head.headLiveness())
.expectNext(HeadLivenessState.FATAL_ERROR)
.thenCancel()
.verify(Duration.ofSeconds(3))
}
.thenCancel() .thenCancel()
.verify(Duration.ofSeconds(3)) .verify(Duration.ofSeconds(3))
assertThat(head.getCurrentHeight()).isEqualTo(10000)
verify(reader, times(2)).read(ChainRequest("eth_getBlockByNumber", ListParams("latest", false))) verify(reader, times(2)).read(ChainRequest("eth_getBlockByNumber", ListParams("latest", false)))
verify(reader).read(ChainRequest("eth_chainId", ListParams())) verify(reader).read(ChainRequest("eth_chainId", ListParams()))
verify(reader).read(ChainRequest("net_version", ListParams())) verify(reader).read(ChainRequest("net_version", ListParams()))