1

I'm using WebTestClient to do some integration testing of a controller. If I set a breakpoint inside the controller I hit the standard timeout of 5s of the WebTestClient. The solution to this is to add @AutoConfigureWebTestClient(timeout = "600000") to my test as stated her Timeout on blocking read for 5000 MILLISECONDS in Spring WEBFLUX.

For me @AutoConfigureWebTestClient(timeout = "600000") does not change anything. I still get the timout exception after 5s.

Any ideas what's wrong?

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@ActiveProfiles("test")
@Transactional
@Import(EntityFactoryConfiguration.class)
@AutoConfigureWebTestClient(timeout = "600000") // giv me 10 min for debugging
public class LogControllerIntegrationTest {

    ...

    @Autowired
    private WebTestClient webTestClient;

    ...

    @Test
    public void myTest() {
        ...
        webTestClient.post().uri("/log")
                .contentType(MediaType.APPLICATION_JSON_UTF8)
                .accept(MediaType.APPLICATION_JSON_UTF8)
                .body(BodyInserters.fromObject(protocolLine))
                .exchange()
                .expectStatus().isOk();

    }
BetaRide
  • 16,207
  • 29
  • 99
  • 177

3 Answers3

3

I think that annotation does not work in your setup, since by default the timeout is already 5 seconds, how about trying the other answer of that linked question?

@BeforeEach
public void setUp() {
     webTestClient = webTestClient
                        .mutate()
                        .responseTimeout(Duration.ofMillis(600000))
                        .build();
}

You can see from its name @AutoConfigureWebTestClient is trying to configure WebTestClient automatically, but I think you somehow override it by autowiring the WebTestClient and maybe configuring it as well? So go ahead and set the timeout manually as well!

update

Afaics, just adding spring-boot-starter-webflux as dependency should be sufficient to get a WebTestClient bean, so no need to even have @AutoConfigureWebTestClient I think. Check this. Can you confirm this?

buræquete
  • 14,226
  • 4
  • 44
  • 89
  • Ok, mutating my WebTestClient instance works. But how is the `@AutoConfigureWebTestClient` supposed to work if I should not use `@Autowired`? – BetaRide Jun 27 '19 at 07:00
  • @BetaRide I think just autowiring should not break it, do you configure it or mutate it at any other place? I updated regarding `@AutoConfigureWebTestClient` can you check it? – buræquete Jun 27 '19 at 07:58
  • No, I do not mutate the WebTestClient anywehre else. So I stil don't understand why `@AutoConfigureWebTestClient` exists if it's not supposed to work with `@Autowired`. – BetaRide Jun 27 '19 at 08:14
  • @BetaRide did you try to run the tests without adding @AutoConfigureWebTestClient? Can WebTestClient be autowired w/o it? I cannot test now, sorry. `AutoConfigureWebTestClient` class itself looks very limited, and is not really well documented as well, maybe it is better not to use it, if you can make it work w/o it? – buræquete Jun 27 '19 at 08:29
  • Sorry, if this wasn't clear! Everything works accoring to your answer. Just mutate the response time and don't use `@AutoConfigureWebTestClient`. I'm just curious why the annotation exists at all. But maybe I'm just to curious. – BetaRide Jun 27 '19 at 08:45
  • @BetaRide I also do not know the reason, and couldn't find anything about that... Maybe it was used properly before, but now about to get deprecated? If this has resolved your case, can you accept it as solved? If I can find any more detail, I will share with you about that useless annotation =) – buræquete Jul 05 '19 at 02:08
2

@AutoConfigureWebTestClient does not accept value of milliseconds, but rather string which is parsed into Duration, using

Duration.parse(CharSequence)

As stated in the Javadoc for @AutoConfigureWebTestClient

The timeout duration for the client (in any format handled by Duration.parse(CharSequence)).

The format for duration string is explained at Duration Javadoc

To set a timeout of 10 minutes you should specify the following:

@AutoConfigureWebTestClient(timeout = "PT10M")
1

I know its been a year now since the question was asked. But as of now this annotation works well with a given timeout Here is my configuration

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@AutoConfigureWebTestClient(timeout = "10000")
@ActiveProfiles("test")
public class SomeIntegrationTests {

    @Autowired
    private WebTestClient webClient;

Maybe an old bug that is resolved now..

Özgün
  • 318
  • 3
  • 11
  • No, it still doesn't work. The timeout is set as demanded but the exception from the blocking execute() still causes a java.lang.IllegalStateException: Timeout on blocking read for 100000 MILLISECONDS... – du-it Sep 30 '21 at 18:32