From f3e3e5f550805fa8072c0a4b5f96012569ceb093 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Thu, 22 Dec 2022 15:00:38 +0100 Subject: [PATCH 1/2] First attempt at fixing intermittent test failure, repeated test to verify. --- tests/integration/webclient/pom.xml | 7 ++++- .../webclient/TracingPropagationTest.java | 27 ++++++++++++------- .../integration/webclient/TracingTest.java | 2 +- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tests/integration/webclient/pom.xml b/tests/integration/webclient/pom.xml index e7e70103966..a34269ac2de 100644 --- a/tests/integration/webclient/pom.xml +++ b/tests/integration/webclient/pom.xml @@ -16,7 +16,7 @@ --> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> helidon-tests-integration io.helidon.tests.integration @@ -95,5 +95,10 @@ opentracing-mock test + + helidon-common-testing-junit5 + io.helidon.common.testing + test + diff --git a/tests/integration/webclient/src/test/java/io/helidon/tests/integration/webclient/TracingPropagationTest.java b/tests/integration/webclient/src/test/java/io/helidon/tests/integration/webclient/TracingPropagationTest.java index 0e8f0e95ee2..9085aa58598 100644 --- a/tests/integration/webclient/src/test/java/io/helidon/tests/integration/webclient/TracingPropagationTest.java +++ b/tests/integration/webclient/src/test/java/io/helidon/tests/integration/webclient/TracingPropagationTest.java @@ -20,10 +20,12 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import io.helidon.common.context.Context; +import io.helidon.common.http.Http; +import io.helidon.common.testing.junit5.MatcherWithRetry; import io.helidon.config.Config; +import io.helidon.reactive.media.jsonp.JsonpSupport; import io.helidon.reactive.webclient.WebClient; import io.helidon.reactive.webclient.WebClientResponse; import io.helidon.reactive.webserver.WebServer; @@ -32,14 +34,15 @@ import io.opentracing.mock.MockSpan; import io.opentracing.mock.MockTracer; import io.opentracing.tag.Tags; +import jakarta.json.JsonObject; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.RepeatedTest; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasSize; /** * Test tracing integration. @@ -47,8 +50,7 @@ class TracingPropagationTest { private static final Duration TIMEOUT = Duration.ofSeconds(10); - @Test - @Disabled // intermittently failing on pipeline, issue 5754 + @RepeatedTest(100) void testTracingSuccess() throws ExecutionException, InterruptedException { MockTracer mockTracer = new MockTracer(); @@ -63,18 +65,23 @@ void testTracingSuccess() throws ExecutionException, InterruptedException { .baseUri(uri) .context(context) .config(Config.create().get("client")) + .addMediaSupport(JsonpSupport.create()) .build(); - client.get() + WebClientResponse response = client.get() .queryParam("some", "value") .fragment("fragment") .request() - .forSingle(WebClientResponse::close) .await(TIMEOUT); + assertThat(response.status(), is(Http.Status.OK_200)); + assertThat(response.content().as(JsonObject.class).await(TIMEOUT), notNullValue()); + response.close(); + + // the server traces asynchronously, some spans may be written after we receive the response. + // we need to try to wait for such spans + MatcherWithRetry.assertThatWithRetry("There should be 3 spans reported", mockTracer::finishedSpans, hasSize(3)); - TimeUnit.MILLISECONDS.sleep(1); List mockSpans = mockTracer.finishedSpans(); - assertThat("At least one client and one server span expected", mockSpans.size(), greaterThanOrEqualTo(2)); // we need the first span - parentId 0 MockSpan clientSpan = findSpanWithParentId(mockSpans, 0); diff --git a/tests/integration/webclient/src/test/java/io/helidon/tests/integration/webclient/TracingTest.java b/tests/integration/webclient/src/test/java/io/helidon/tests/integration/webclient/TracingTest.java index c56aad9ab41..81fbd5a70e0 100644 --- a/tests/integration/webclient/src/test/java/io/helidon/tests/integration/webclient/TracingTest.java +++ b/tests/integration/webclient/src/test/java/io/helidon/tests/integration/webclient/TracingTest.java @@ -45,7 +45,7 @@ class TracingTest extends TestParent { private static final Duration TIMEOUT = Duration.ofSeconds(30); @Test - void testTracingNoServerSuccess() throws ExecutionException, InterruptedException { + void testTracingNoServerSuccess() { MockTracer mockTracer = new MockTracer(); String uri = "http://localhost:" + webServer.port() + "/greet"; Context context = Context.builder().id("tracing-unit-test").build(); From 11aba48a2a7d8146c46c9b30a1dcb2c0702cdcf4 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Thu, 22 Dec 2022 15:44:48 +0100 Subject: [PATCH 2/2] Removed repeated test. --- .../tests/integration/webclient/TracingPropagationTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/webclient/src/test/java/io/helidon/tests/integration/webclient/TracingPropagationTest.java b/tests/integration/webclient/src/test/java/io/helidon/tests/integration/webclient/TracingPropagationTest.java index 9085aa58598..2b3feecca90 100644 --- a/tests/integration/webclient/src/test/java/io/helidon/tests/integration/webclient/TracingPropagationTest.java +++ b/tests/integration/webclient/src/test/java/io/helidon/tests/integration/webclient/TracingPropagationTest.java @@ -36,7 +36,7 @@ import io.opentracing.tag.Tags; import jakarta.json.JsonObject; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.RepeatedTest; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -50,7 +50,7 @@ class TracingPropagationTest { private static final Duration TIMEOUT = Duration.ofSeconds(10); - @RepeatedTest(100) + @Test void testTracingSuccess() throws ExecutionException, InterruptedException { MockTracer mockTracer = new MockTracer();