From 3eb1947573d13758e18c1d2cc1cd7fdd46131b49 Mon Sep 17 00:00:00 2001 From: brunobat Date: Thu, 16 Jan 2025 15:38:19 +0000 Subject: [PATCH 1/2] Speed up test --- .../deployment/traces/MutinyTracingHelperTest.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/traces/MutinyTracingHelperTest.java b/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/traces/MutinyTracingHelperTest.java index 58313b1442200..a025603fda2de 100644 --- a/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/traces/MutinyTracingHelperTest.java +++ b/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/traces/MutinyTracingHelperTest.java @@ -3,6 +3,7 @@ import static io.quarkus.opentelemetry.runtime.tracing.mutiny.MutinyTracingHelper.wrapWithSpan; import static org.assertj.core.api.Assertions.assertThat; +import java.time.Duration; import java.util.List; import java.util.Optional; import java.util.stream.Stream; @@ -12,7 +13,7 @@ import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -42,7 +43,10 @@ class MutinyTracingHelperTest { () -> ShrinkWrap.create(JavaArchive.class) .addClasses(TestSpanExporter.class, TestSpanExporterProvider.class) .addAsResource(new StringAsset(TestSpanExporterProvider.class.getCanonicalName()), - "META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider")); + "META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider") + .addAsResource(new StringAsset( + "quarkus.otel.bsp.schedule.delay=50ms\n"), + "application.properties")); @Inject private TestSpanExporter spanExporter; @@ -53,7 +57,7 @@ class MutinyTracingHelperTest { @Inject private Vertx vertx; - @AfterEach + @BeforeEach void tearDown() { spanExporter.reset(); } @@ -148,7 +152,7 @@ void testNestedPipeline_implicitParent(final String contextType, .subscribe() .withSubscriber(new UniAssertSubscriber<>()); - subscriber.awaitItem(); + subscriber.awaitItem(Duration.ofMillis(300)); //ensure there are 2 spans with doSomething and doSomethingAsync as children of testSpan final List spans = spanExporter.getFinishedSpanItems(2); @@ -178,7 +182,7 @@ void testNestedPipeline_explicitNoParent(final String contextType, final String .subscribe() .withSubscriber(new UniAssertSubscriber<>()); - subscriber.awaitItem(); + subscriber.awaitItem(Duration.ofMillis(300)); //ensure there are 2 spans but without parent-child relationship final List spans = spanExporter.getFinishedSpanItems(2); From d605c315847cc60f340b272f64519eb059c29de8 Mon Sep 17 00:00:00 2001 From: brunobat Date: Thu, 16 Jan 2025 16:10:26 +0000 Subject: [PATCH 2/2] Fix flaky otel quickstart test --- .../OpenTelemetryDisabledTest.java | 19 ++++++++++++++++++- .../it/opentelemetry/OpenTelemetryTest.java | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/integration-tests/opentelemetry-quickstart/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryDisabledTest.java b/integration-tests/opentelemetry-quickstart/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryDisabledTest.java index 92a8e66aa8537..fb2e5a34c0364 100644 --- a/integration-tests/opentelemetry-quickstart/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryDisabledTest.java +++ b/integration-tests/opentelemetry-quickstart/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryDisabledTest.java @@ -2,12 +2,16 @@ 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.MILLISECONDS; +import static java.util.concurrent.TimeUnit.SECONDS; import static org.awaitility.Awaitility.await; import static org.hamcrest.CoreMatchers.is; +import java.util.List; import java.util.Map; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import io.quarkus.test.junit.QuarkusTest; @@ -18,6 +22,19 @@ @TestProfile(OpenTelemetryDisabledTest.MyProfile.class) public class OpenTelemetryDisabledTest extends BaseTest { + @BeforeEach + void reset() { + await().atMost(5, SECONDS).until(() -> { + List> spans = getSpans(); + if (spans.size() == 0) { + return true; + } else { + given().get("/reset").then().statusCode(HTTP_OK); + return false; + } + }); + } + @Test void buildTimeDisabled() { given() @@ -26,7 +43,7 @@ void buildTimeDisabled() { .statusCode(200) .body(is("Hello from Quarkus REST")); // Service will start nevertheless. - await().atMost(200, MILLISECONDS).until(() -> getSpans().size() == 0); + await().atMost(300, MILLISECONDS).until(() -> getSpans().size() == 0); } public static class MyProfile implements QuarkusTestProfile { diff --git a/integration-tests/opentelemetry-quickstart/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryTest.java b/integration-tests/opentelemetry-quickstart/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryTest.java index e4963ec759d1e..746a31747db2b 100644 --- a/integration-tests/opentelemetry-quickstart/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryTest.java +++ b/integration-tests/opentelemetry-quickstart/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryTest.java @@ -2,16 +2,35 @@ 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.is; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import io.quarkus.test.junit.QuarkusTest; @QuarkusTest public class OpenTelemetryTest extends BaseTest { + + @BeforeEach + void reset() { + await().atMost(5, SECONDS).until(() -> { + List> spans = getSpans(); + if (spans.size() == 0) { + return true; + } else { + given().get("/reset").then().statusCode(HTTP_OK); + return false; + } + }); + } + @Test void buildTimeEnabled() { given()