Skip to content

Commit

Permalink
4.x: Intermittent failure (WebClient tracing test) (#5755)
Browse files Browse the repository at this point in the history
* Now checking results with retries, as tracing may be asynchronous server side
  • Loading branch information
tomas-langer authored Dec 23, 2022
1 parent 3e93881 commit 5f35daf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
7 changes: 6 additions & 1 deletion tests/integration/webclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>helidon-tests-integration</artifactId>
<groupId>io.helidon.tests.integration</groupId>
Expand Down Expand Up @@ -95,5 +95,10 @@
<artifactId>opentracing-mock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<artifactId>helidon-common-testing-junit5</artifactId>
<groupId>io.helidon.common.testing</groupId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 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.
Expand All @@ -48,7 +51,6 @@ class TracingPropagationTest {
private static final Duration TIMEOUT = Duration.ofSeconds(10);

@Test
@Disabled // intermittently failing on pipeline, issue 5754
void testTracingSuccess() throws ExecutionException, InterruptedException {
MockTracer mockTracer = new MockTracer();

Expand All @@ -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<MockSpan> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5f35daf

Please sign in to comment.