Skip to content

Commit

Permalink
fix(test): Fix dns daemon periodic test (#7200)
Browse files Browse the repository at this point in the history
* fix(test): Fix dns daemon periodic test

Increase second run to 3 seconds

Signed-off-by: Usman Saleem <[email protected]>

* fix(test): Fix dns daemon periodic test

change vertx testContext verify to failNow

Signed-off-by: Usman Saleem <[email protected]>

* fix(test): Fix dns daemon periodic test

Remove Disabled

Signed-off-by: Usman Saleem <[email protected]>

* fix(test): Code formatting

Signed-off-by: Usman Saleem <[email protected]>

---------

Signed-off-by: Usman Saleem <[email protected]>
  • Loading branch information
usmansaleem authored Jun 12, 2024
1 parent a8621f4 commit c7e2e4d
Showing 1 changed file with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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");
Expand All @@ -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 =
Expand Down

0 comments on commit c7e2e4d

Please sign in to comment.