Skip to content

Commit

Permalink
Fix flacky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobat committed Sep 9, 2024
1 parent 65eb49e commit 9799655
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -41,8 +42,14 @@ public class OpenTelemetryReactiveTest {
@BeforeEach
@AfterEach
void reset() {
given().get("/reset").then().statusCode(HTTP_OK);
await().atMost(5, SECONDS).until(() -> getSpans().size() == 0);
await().atMost(Duration.ofSeconds(30L)).until(() -> {
// make sure spans are cleared
List<Map<String, Object>> spans = getSpans();
if (!spans.isEmpty()) {
given().get("/reset").then().statusCode(HTTP_OK);
}
return spans.isEmpty();
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static io.restassured.RestAssured.get;
import static io.restassured.RestAssured.given;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -33,8 +32,14 @@ public class OTelSpiTest {
@BeforeEach
@AfterEach
void reset() {
given().get("/reset").then().statusCode(HTTP_OK);
await().atMost(5, SECONDS).until(() -> getSpans().size() == 0);
await().atMost(Duration.ofSeconds(30L)).until(() -> {
// make sure spans are cleared
List<Map<String, Object>> spans = getSpans();
if (!spans.isEmpty()) {
given().get("/reset").then().statusCode(HTTP_OK);
}
return spans.isEmpty();
});
}

private List<Map<String, Object>> getSpans() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.await;

import java.time.Duration;
import java.util.List;
import java.util.Map;

Expand All @@ -22,8 +23,14 @@ public class OpenTelemetryInjectionsTest {
@BeforeEach
@AfterEach
void reset() {
given().get("/reset").then().statusCode(HTTP_OK);
await().atMost(5, SECONDS).until(() -> getSpans().size() == 0);
await().atMost(Duration.ofSeconds(30L)).until(() -> {
// make sure spans are cleared
List<Map<String, Object>> spans = getSpans();
if (!spans.isEmpty()) {
given().get("/reset").then().statusCode(HTTP_OK);
}
return spans.isEmpty();
});
}

private List<Map<String, Object>> getSpans() {
Expand Down

0 comments on commit 9799655

Please sign in to comment.