Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky OTel tests #43142

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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