Closed
Description
Running the test class below with spring-boot 3.3.10 all cases pass, but with spring-boot 3.4.4 the test retryWithObservationRegistryFails()
fails with the following error:
Expecting actual throwable to be an instance of:
org.springframework.web.reactive.function.client.WebClientResponseException
but was:
io.micrometer.observation.tck.InvalidObservationException: Invalid start: Observation 'http.client.requests' has already been started
START: org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.lambda$exchange$12(DefaultWebClient.java:458)
STOP: org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.lambda$exchange$10(DefaultWebClient.java:484)
START: org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.lambda$exchange$12(DefaultWebClient.java:458)
START: org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.lambda$exchange$12(DefaultWebClient.java:458)
START: org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.lambda$exchange$12(DefaultWebClient.java:458)
at io.micrometer.observation.tck.ObservationValidator.throwInvalidObservationException(ObservationValidator.java:149)
at io.micrometer.observation.tck.ObservationValidator.onStart(ObservationValidator.java:64)
at io.micrometer.observation.SimpleObservation.notifyOnObservationStarted(SimpleObservation.java:214)
...(107 remaining lines not displayed - this can be changed with Assertions.setMaxStackTraceElementsDisplayed)
at com.example.demo.DemoApplicationTests.retryWithObservationRegistryFails(DemoApplicationTests.java:44)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Reproduction example
package com.example.demo;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import org.junit.jupiter.api.Test;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import io.micrometer.observation.tck.TestObservationRegistry;
class DemoApplicationTests {
private final WebClient.Builder webclientBuilder = WebClient.builder()
.baseUrl("https://httpstat.us/500");
private final WebClient webClientNoObservationRegistry = webclientBuilder
.build();
private final WebClient webClient = webclientBuilder
.observationRegistry(TestObservationRegistry.create())
.build();
@Test
void noRetryWorks() {
assertThatExceptionOfType(WebClientResponseException.class).isThrownBy(() ->
webClient.get().retrieve()
.bodyToMono(String.class)
.block()
);
}
@Test
void retryWithoutObservationRegistryWorks() {
assertThatExceptionOfType(WebClientResponseException.class).isThrownBy(() ->
webClientNoObservationRegistry.get().retrieve()
.bodyToMono(String.class)
.retry(3)
.block()
);
}
@Test
void retryWithObservationRegistryFails() {
assertThatExceptionOfType(WebClientResponseException.class).isThrownBy(() ->
webClient.get().retrieve()
.bodyToMono(String.class)
.retry(3)
.block()
);
}
}