diff --git a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/instrument/web/client/feign/TraceNoWebEnvironmentTests.java b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/instrument/web/client/feign/TraceNoWebEnvironmentTests.java index 301d71f81..9c9b1794d 100644 --- a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/instrument/web/client/feign/TraceNoWebEnvironmentTests.java +++ b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/instrument/web/client/feign/TraceNoWebEnvironmentTests.java @@ -47,7 +47,8 @@ public class TraceNoWebEnvironmentTests { client.createSomeTestRequest(); } catch (Exception e) { - then(e.getCause().getClass()).isNotEqualTo(NoSuchBeanDefinitionException.class); + Throwable cause = e.getCause() != null ? e.getCause() : e; + then(cause.getClass()).isNotEqualTo(NoSuchBeanDefinitionException.class); } } diff --git a/tests/common/src/main/java/org/springframework/cloud/sleuth/instrument/annotation/SleuthSpanCreatorAspectFluxTests.java b/tests/common/src/main/java/org/springframework/cloud/sleuth/instrument/annotation/SleuthSpanCreatorAspectFluxTests.java index fcc9b2e2c..0ce103c14 100644 --- a/tests/common/src/main/java/org/springframework/cloud/sleuth/instrument/annotation/SleuthSpanCreatorAspectFluxTests.java +++ b/tests/common/src/main/java/org/springframework/cloud/sleuth/instrument/annotation/SleuthSpanCreatorAspectFluxTests.java @@ -25,6 +25,7 @@ import java.util.stream.Collectors; import org.assertj.core.api.BDDAssertions; import org.awaitility.Awaitility; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; @@ -84,6 +85,7 @@ public abstract class SleuthSpanCreatorAspectFluxTests { } @BeforeEach + @AfterEach public void setup() { this.spans.clear(); this.testBean.reset(); diff --git a/tests/common/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/integration/sampled/WebClientTests.java b/tests/common/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/integration/sampled/WebClientTests.java index 2aacd3eeb..68b15e85e 100644 --- a/tests/common/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/integration/sampled/WebClientTests.java +++ b/tests/common/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/integration/sampled/WebClientTests.java @@ -130,6 +130,11 @@ public abstract class WebClientTests { this.fooController.clear(); } + @BeforeEach + public void setup() { + log.info("Starting test"); + } + @ParameterizedTest @MethodSource("parametersForShouldCreateANewSpanWithClientSideTagsWhenNoPreviousTracingWasPresent") @SuppressWarnings("unchecked") @@ -150,6 +155,11 @@ public abstract class WebClientTests { // at the interceptor level then(noTraceSpan.get().getTags().get("http.path")).matches(".*/notrace"); }); + thenThereIsNoCurrentSpan(); + } + + private void thenThereIsNoCurrentSpan() { + log.info("Current span [" + this.tracer.currentSpan() + "]"); then(this.tracer.currentSpan()).isNull(); } @@ -197,7 +207,7 @@ public abstract class WebClientTests { span.end(); } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.spans).isNotEmpty(); } @@ -213,7 +223,7 @@ public abstract class WebClientTests { finally { span.end(); } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.spans.reportedSpans().stream().filter(r -> r.getKind() != null).map(r -> r.getKind().name()) .collect(Collectors.toList())).isNotEmpty().contains("CLIENT"); } @@ -234,7 +244,7 @@ public abstract class WebClientTests { span.end(); } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.spans.reportedSpans().stream().filter(r -> r.getKind() != null).map(r -> r.getKind().name()) .collect(Collectors.toList())).isNotEmpty().contains("CLIENT"); } @@ -286,7 +296,7 @@ public abstract class WebClientTests { span.end(); } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.spans).isNotEmpty(); } @@ -305,7 +315,7 @@ public abstract class WebClientTests { catch (HttpClientErrorException e) { } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); Optional storedSpan = this.spans.reportedSpans().stream() .filter(span -> "404".equals(span.getTags().get("http.status_code"))).findFirst(); then(storedSpan.isPresent()).isTrue(); @@ -325,7 +335,7 @@ public abstract class WebClientTests { public void shouldNotExecuteErrorControllerWhenUrlIsFound() { this.template.getForEntity("http://fooservice/notrace", String.class); - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.testErrorController.getSpan()).isNull(); } @@ -341,7 +351,7 @@ public abstract class WebClientTests { finally { span.end(); } - then(this.tracer.currentSpan()).isNull(); + thenThereIsNoCurrentSpan(); then(this.customizer.isExecuted()).isTrue(); then(this.spans).extracting("kind.name").contains("CLIENT"); }