Skip to content

WebTestClient is now bound to previous test server port when test application context is paused #46557

@trecloux

Description

@trecloux

Hi Spring Boot team :-)

I gave a try to spring boot 4.0.0-M1 on one of our projects.

We are using spring-mvc but we are using WebTestClient to use the fluent API in integration tests.

After the upgrade, I started observing failures on integration tests.

I built a minimal application to reproduce the problem, here are the sources: https://github.com/trecloux/spring-boot-4.0.0-M1-integration-test

This application includes two identical tests, when launching both tests using IntelliJ or gradle, the second test is always failing.

First test logs extract

2025-07-27T22:46:35.039+02:00  INFO 95158 --- [    Test worker] o.s.boot.tomcat.TomcatWebServer          : Tomcat started on port 58520 (http) with context path '/'
...
2025-07-27T22:46:37.699+02:00  INFO 95158 --- [tomcat-shutdown] o.s.boot.tomcat.GracefulShutdown         : Graceful shutdown complete

Second test logs extract

2025-07-27T22:46:37.715+02:00  INFO 95158 --- [    Test worker] o.s.boot.tomcat.TomcatWebServer          : Tomcat started on port 58524 (http) with context path '/'
....
Connection refused: localhost/[0:0:0:0:0:0:0:1]:58520
org.springframework.web.reactive.function.client.WebClientRequestException: Connection refused: localhost/[0:0:0:0:0:0:0:1]:58520

It looks like the second test WebTestClient is binded to first test web server (port 58520 instead of 58524).

I checked that with version 3.5.4, the sample application's test are OK. Comparing logs, it looks like embedded tomcat is started only once with spring boot 3.5.4,

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions