From 79d2969930334e554cf081989f0cc2fc13b9d6e2 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 26 Feb 2021 09:58:16 +0100 Subject: [PATCH 1/4] Added debug info --- .../client/integration/WebClientTests.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/integration/WebClientTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/integration/WebClientTests.java index 9f7e468b5..a044f57d5 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/integration/WebClientTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/integration/WebClientTests.java @@ -58,6 +58,7 @@ import org.junit.ClassRule; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; import org.junit.runner.RunWith; import org.reactivestreams.Subscription; import reactor.core.publisher.BaseSubscriber; @@ -167,6 +168,11 @@ public class WebClientTests { this.testErrorController.clear(); this.fooController.clear(); } + + @Before + public void setup() { + log.info("Starting test"); + } @Test @Parameters @@ -191,6 +197,11 @@ public class WebClientTests { // at the interceptor level then(noTraceSpan.get().tags().get("http.url")).matches(".*/notrace"); }); + thenThereIsNoCurrentSpan(); + } + + private void thenThereIsNoCurrentSpan() { + log.info("Current span [" + this.tracer.currentSpan() + "]"); then(this.tracer.currentSpan()).isNull(); } @@ -241,7 +252,7 @@ public class WebClientTests { } then(this.spans).isEmpty(); - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); } Object[] parametersForShouldPropagateNotSamplingHeader() throws Exception { @@ -270,7 +281,7 @@ public class WebClientTests { span.finish(); } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.spans).isNotEmpty(); } @@ -288,7 +299,7 @@ public class WebClientTests { then(response).isNotEmpty(); } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.spans).isNotEmpty().extracting("traceId", String.class) .containsOnly(span.context().traceIdString()); then(this.spans).extracting("kind.name").contains("CLIENT"); @@ -327,7 +338,7 @@ public class WebClientTests { client.close(); } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.spans).isNotEmpty().extracting("traceId", String.class) .containsOnly(span.context().traceIdString()); then(this.spans).extracting("kind.name").contains("CLIENT"); @@ -345,7 +356,7 @@ public class WebClientTests { finally { span.finish(); } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.spans).isNotEmpty().extracting("kind.name").contains("CLIENT"); } @@ -365,7 +376,7 @@ public class WebClientTests { span.finish(); } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.spans).isNotEmpty().extracting("kind.name").contains("CLIENT"); } @@ -419,7 +430,7 @@ public class WebClientTests { span.finish(); } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.spans).isNotEmpty(); } @@ -440,7 +451,7 @@ public class WebClientTests { catch (HttpClientErrorException e) { } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); Optional storedSpan = this.spans.spans().stream() .filter(span -> "404".equals(span.tags().get("http.status_code"))) .findFirst(); @@ -461,7 +472,7 @@ public class WebClientTests { public void shouldNotExecuteErrorControllerWhenUrlIsFound() { this.template.getForEntity("http://fooservice/notrace", String.class); - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.testErrorController.getSpan()).isNull(); } @@ -478,7 +489,7 @@ public class WebClientTests { finally { span.finish(); } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.customizer.isExecuted()).isTrue(); then(this.spans).extracting("kind.name").contains("CLIENT"); } From 1c6c1ce666f3c73cf9b0124091b797a55c7111f4 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 26 Feb 2021 10:00:22 +0100 Subject: [PATCH 2/4] Fixed checkstyle --- .../sleuth/instrument/web/client/integration/WebClientTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/integration/WebClientTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/integration/WebClientTests.java index a044f57d5..d656c86d0 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/integration/WebClientTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/integration/WebClientTests.java @@ -58,7 +58,6 @@ import org.junit.ClassRule; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; -import org.junit.jupiter.api.BeforeEach; import org.junit.runner.RunWith; import org.reactivestreams.Subscription; import reactor.core.publisher.BaseSubscriber; From 081171b699f1e91612d1423cedf60024ce095387 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 26 Feb 2021 10:13:38 +0100 Subject: [PATCH 3/4] Should clear scope after flux test --- .../sleuth/annotation/SleuthSpanCreatorAspectFluxTests.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectFluxTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectFluxTests.java index 43b3c720e..c2d54f04f 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectFluxTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectFluxTests.java @@ -32,6 +32,7 @@ import brave.sampler.Sampler; import brave.test.TestSpanHandler; import org.apache.commons.lang3.StringUtils; import org.awaitility.Awaitility; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -89,10 +90,11 @@ public class SleuthSpanCreatorAspectFluxTests { } @Before + @After public void setup() { this.spans.clear(); this.testBean.reset(); - tracer.withSpanInScope(null); + this.tracer.withSpanInScope(null); } @Test From 4b123747b302479e063b09d590d22f785d668502 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 26 Feb 2021 10:20:53 +0100 Subject: [PATCH 4/4] Making tests less brittle --- .../sleuth/instrument/web/TraceNoWebEnvironmentTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceNoWebEnvironmentTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceNoWebEnvironmentTests.java index 8f6c18ee8..5def5459f 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceNoWebEnvironmentTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceNoWebEnvironmentTests.java @@ -48,7 +48,8 @@ public class TraceNoWebEnvironmentTests { client.createSomeTestRequest(); } catch (Exception e) { - then(e.getCause().getClass()) + Throwable cause = e.getCause() != null ? e.getCause() : e; + then(cause.getClass()) .isNotEqualTo(NoSuchBeanDefinitionException.class); } }