From 79408d7b2c6d15cc81ec2875cd1b46bdbd729f6b Mon Sep 17 00:00:00 2001 From: abilan Date: Wed, 7 Jun 2023 19:10:47 -0400 Subject: [PATCH] Fix observation race condition in WebFlux test There is a race condition when we already have a reply, but the span in the last channel is not closed yet. --- .../observation/WebFluxObservationPropagationTests.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/observation/WebFluxObservationPropagationTests.java b/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/observation/WebFluxObservationPropagationTests.java index beafe63cfc..7588c62c6c 100644 --- a/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/observation/WebFluxObservationPropagationTests.java +++ b/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/observation/WebFluxObservationPropagationTests.java @@ -63,6 +63,7 @@ import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; /** * @author Artem Bilan @@ -123,7 +124,8 @@ public class WebFluxObservationPropagationTests { .expectBody(String.class) .isEqualTo(testData.toLowerCase()); - assertThat(SPANS.spans()).hasSize(3); + // There is a race condition when we already have a reply, but the span in the last channel is not closed yet. + await().untilAsserted(() -> assertThat(SPANS.spans()).hasSize(3)); SpansAssert.assertThat(SPANS.spans().stream().map(BraveFinishedSpan::fromBrave).collect(Collectors.toList())) .haveSameTraceId(); }