From 2fefd75fb72ba1bc6c9fc683898793891e66a5c7 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Wed, 17 Apr 2019 08:03:50 +0400 Subject: [PATCH] Made tests less brittle --- .../instrument/messaging/ITTracingChannelInterceptor.java | 7 +------ .../instrument/scheduling/TracingOnScheduledTests.java | 3 ++- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/messaging/ITTracingChannelInterceptor.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/messaging/ITTracingChannelInterceptor.java index 1674b9252..7f6a5f8af 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/messaging/ITTracingChannelInterceptor.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/messaging/ITTracingChannelInterceptor.java @@ -32,6 +32,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -40,12 +41,10 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.ExecutorChannel; -import org.springframework.integration.config.GlobalChannelInterceptor; import org.springframework.integration.core.MessagingTemplate; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; -import org.springframework.messaging.support.ChannelInterceptor; import org.springframework.messaging.support.MessageHeaderAccessor; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; @@ -166,9 +165,5 @@ public class ITTracingChannelInterceptor implements MessageHandler { return new MessagingTemplate(directChannel()); } - @Bean @GlobalChannelInterceptor - public ChannelInterceptor tracingChannelInterceptor(Tracing tracing) { - return TracingChannelInterceptor.create(tracing); - } } } \ No newline at end of file diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/scheduling/TracingOnScheduledTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/scheduling/TracingOnScheduledTests.java index df02de55e..baedec01d 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/scheduling/TracingOnScheduledTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/scheduling/TracingOnScheduledTests.java @@ -70,6 +70,7 @@ public class TracingOnScheduledTests { } @Test + @DirtiesContext public void should_have_span_set_after_scheduled_method_has_been_executed() { await().atMost(10, SECONDS).untilAsserted(() -> { then(this.beanWithScheduledMethod.isExecuted()).isTrue(); @@ -109,7 +110,7 @@ public class TracingOnScheduledTests { then(storedSpan).isNotNull(); then(storedSpan.context().traceId()).isNotNull(); zipkin2.Span foundSpan = this.reporter.getSpans().stream() - .filter(span -> !span.tags().containsKey("error")) + .filter(span -> !span.tags().containsKey("error") && span.tags().containsValue("TestBeanWithScheduledMethod")) .findFirst().orElseThrow(() -> new AssertionError("Span is missing")); then(foundSpan.tags()) .contains(new AbstractMap.SimpleEntry<>("class", "TestBeanWithScheduledMethod"),