From be5336054020a9a69c13397c4c966af876555b54 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 13 Nov 2024 11:21:48 -0500 Subject: [PATCH] Fix race condition in the `ObservationTests` The listener may also report its span before we assert against current `tracer.getSpans()` --- .../kafka/support/micrometer/ObservationTests.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/ObservationTests.java b/spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/ObservationTests.java index ce9acf3de2..0a48bf63fd 100644 --- a/spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/ObservationTests.java +++ b/spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/ObservationTests.java @@ -153,6 +153,9 @@ public void configure(Map configs) { } }); + MessageListenerContainer listenerContainer1 = rler.getListenerContainer("obs1"); + listenerContainer1.stop(); + template.send(OBSERVATION_TEST_1, "test") .thenAccept((sendResult) -> spanFromCallback.set(tracer.currentSpan())) .get(10, TimeUnit.SECONDS); @@ -166,7 +169,7 @@ public void configure(Map configs) { "key", "value")); assertThat(spanFromCallback.get()).isNotNull(); - MessageListenerContainer listenerContainer1 = rler.getListenerContainer("obs1"); + listenerContainer1.start(); MessageListenerContainer listenerContainer2 = rler.getListenerContainer("obs2"); assertThat(listenerContainer1).isNotNull(); assertThat(listenerContainer2).isNotNull();