From 0cf81dbbbd97b65020812c47641243fb14ba8483 Mon Sep 17 00:00:00 2001 From: abilan Date: Wed, 7 Jun 2023 14:12:38 -0400 Subject: [PATCH] Fix `WebFluxObservationPropagationTests` for HTTP The `WebTestClient` was previously binding directly to the web layer (no HTTP layer involved). Because the new instrumentation is done at the HTTP level (it's required to fully capture error handling and more), the test client must bind at the HTTP level with a `Connector`. --- .../WebFluxObservationPropagationTests.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) 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 418c26e36d..beafe63cfc 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 @@ -57,6 +57,7 @@ import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.ChannelInterceptor; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; +import org.springframework.test.web.reactive.server.HttpHandlerConnector; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; @@ -107,8 +108,7 @@ public class WebFluxObservationPropagationTests { this.observationRegistry.getCurrentObservation().stop(); -// assertThat(SPANS.spans()).hasSize(6); - assertThat(SPANS.spans()).hasSize(5); + assertThat(SPANS.spans()).hasSize(6); SpansAssert.assertThat(SPANS.spans().stream().map(BraveFinishedSpan::fromBrave).collect(Collectors.toList())) .haveSameTraceId(); } @@ -123,9 +123,7 @@ public class WebFluxObservationPropagationTests { .expectBody(String.class) .isEqualTo(testData.toLowerCase()); -// assertThat(SPANS.spans()).hasSize(3); - assertThat(SPANS.spans()).hasSize(2); -// System. out .println(SPANS.spans().stream().map(Objects::toString).collect(Collectors.joining("\n"))); + assertThat(SPANS.spans()).hasSize(3); SpansAssert.assertThat(SPANS.spans().stream().map(BraveFinishedSpan::fromBrave).collect(Collectors.toList())) .haveSameTraceId(); } @@ -171,16 +169,12 @@ public class WebFluxObservationPropagationTests { } @Bean - WebTestClient webTestClient(ApplicationContext applicationContext) { - return WebTestClient.bindToApplicationContext(applicationContext).build(); - } - - // TODO This config does not add a SERVER span into a trace - @Bean - public HttpHandler httpHandler(ObservationRegistry registry, ApplicationContext applicationContext) { - return WebHttpHandlerBuilder.applicationContext(applicationContext) - .observationRegistry(registry) - .build(); + WebTestClient webTestClient(ObservationRegistry registry, ApplicationContext applicationContext) { + HttpHandler httpHandler = + WebHttpHandlerBuilder.applicationContext(applicationContext) + .observationRegistry(registry) + .build(); + return WebTestClient.bindToServer(new HttpHandlerConnector(httpHandler)).build(); } @Bean