From c7e2e4dbbf1a3348992d2701465fa0b3521ad96a Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Wed, 12 Jun 2024 10:40:32 +1000 Subject: [PATCH] fix(test): Fix dns daemon periodic test (#7200) * fix(test): Fix dns daemon periodic test Increase second run to 3 seconds Signed-off-by: Usman Saleem * fix(test): Fix dns daemon periodic test change vertx testContext verify to failNow Signed-off-by: Usman Saleem * fix(test): Fix dns daemon periodic test Remove Disabled Signed-off-by: Usman Saleem * fix(test): Code formatting Signed-off-by: Usman Saleem --------- Signed-off-by: Usman Saleem --- .../p2p/discovery/dns/DNSDaemonTest.java | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/dns/DNSDaemonTest.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/dns/DNSDaemonTest.java index 08539d47bf8..fd8ba1382d8 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/dns/DNSDaemonTest.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/dns/DNSDaemonTest.java @@ -29,13 +29,13 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(VertxExtension.class) class DNSDaemonTest { + private static final int EXPECTED_SEQ = 932; private static final String holeskyEnr = "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.holesky.ethdisco.net"; private final MockDnsServerVerticle mockDnsServerVerticle = new MockDnsServerVerticle(); @@ -54,13 +54,24 @@ void prepare(final Vertx vertx, final VertxTestContext vertxTestContext) { @Test @DisplayName("Test DNS Daemon with a mock DNS server") - void testDNSDaemon(final Vertx vertx, final VertxTestContext testContext) - throws InterruptedException { + void testDNSDaemon(final Vertx vertx, final VertxTestContext testContext) { final Checkpoint checkpoint = testContext.checkpoint(); dnsDaemon = new DNSDaemon( holeskyEnr, - (seq, records) -> checkpoint.flag(), + (seq, records) -> { + if (seq != EXPECTED_SEQ) { + testContext.failNow( + String.format( + "Expecting sequence to be %d in first pass but got: %d", + EXPECTED_SEQ, seq)); + } + if (records.size() != 115) { + testContext.failNow( + "Expecting 115 records in first pass but got: " + records.size()); + } + checkpoint.flag(); + }, 0, 0, 0, @@ -74,7 +85,6 @@ void testDNSDaemon(final Vertx vertx, final VertxTestContext testContext) } @Test - @Disabled("this test is flaky") @DisplayName("Test DNS Daemon with periodic lookup to a mock DNS server") void testDNSDaemonPeriodic(final Vertx vertx, final VertxTestContext testContext) throws InterruptedException { @@ -87,18 +97,28 @@ void testDNSDaemonPeriodic(final Vertx vertx, final VertxTestContext testContext (seq, records) -> { switch (pass.incrementAndGet()) { case 1: - testContext.verify( - () -> { - assertThat(seq).isEqualTo(932); - assertThat(records).hasSize(115); - }); + if (seq != EXPECTED_SEQ) { + testContext.failNow( + String.format( + "Expecting sequence to be %d in first pass but got: %d", + EXPECTED_SEQ, seq)); + } + if (records.size() != 115) { + testContext.failNow( + "Expecting 115 records in first pass but got: " + records.size()); + } break; case 2: - testContext.verify( - () -> { - assertThat(seq).isEqualTo(932); - assertThat(records).isEmpty(); - }); + if (seq != EXPECTED_SEQ) { + testContext.failNow( + String.format( + "Expecting sequence to be %d in second pass but got: %d", + EXPECTED_SEQ, seq)); + } + if (!records.isEmpty()) { + testContext.failNow( + "Expecting 0 records in second pass but got: " + records.size()); + } break; default: testContext.failNow("Third pass is not expected"); @@ -107,7 +127,7 @@ void testDNSDaemonPeriodic(final Vertx vertx, final VertxTestContext testContext }, 0, 1, // initial delay - 300, // second lookup after 300 ms (due to Mock DNS server, we are very quick). + 3000, // second lookup after 3 seconds (the thread scheduling can be slower in CI) "localhost:" + mockDnsServerVerticle.port()); final DeploymentOptions options =