Skip to content

test: migrate webapp ITs from TestRestTemplate to RestTestClient - #2404

Open
Ashish-CodeJourney wants to merge 8 commits into
microcks:masterfrom
Ashish-CodeJourney:test/2116-resttestclient-migration
Open

Ashish-CodeJourney wants to merge 8 commits into
microcks:masterfrom
Ashish-CodeJourney:test/2116-resttestclient-migration

Conversation

@Ashish-CodeJourney

@Ashish-CodeJourney Ashish-CodeJourney commented Oct 29, 2026 •

Copy link
Copy Markdown
  • Migrate the webapp integration tests from TestRestTemplate to Spring's RestTestClient.
  • Add restClient and noRedirectRestClient to AbstractBaseIT. Remove @AutoConfigureTestRestTemplate and the TestRestTemplate field from the base class.
  • Use a streaming RestClient for the SSE tests in McpControllerIT and TracingControllerIT, since RestTestClient buffers the full response body and would block on the infinite stream.
  • Use a no-redirect client in RestControllerIT to check the headers-only 302 response.
  • No production code changes.

Test results

  • Full IT suite (mvn -pl webapp -am -Pit test): 69 tests, 0 failures, 0 errors. Same count as master.
  • mvn spotless:apply run before each commit.

Related issue(s)

Fixes #2116

@github-actions

Copy link
Copy Markdown

👋 @Ashish-CodeJourney

Welcome to the Microcks community! 💖

Thanks and congrats 🎉 for opening your first pull request here! Be sure to follow the pull request template or please update it accordingly.

Hope you have a great time there!

try {
restTemplate.execute("/mcp/Petstore+API/1.0.0/sse", HttpMethod.GET, request -> {}, response -> {
streamingRestClient.get().uri("/mcp/Petstore+API/1.0.0/sse").exchange((request, response) -> {
String line;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SSE client thread reads the response body until EOF, but shutdown() on the executor does not close an active response. The server-side emitter has a 600-second timeout (new SseEmitter(Duration.ofSeconds(600).toMillis()) in McpController). Could we retain the active response/stream and explicitly close it during teardown so the read loop can terminate promptly rather than relying on the server timeout?

HttpMethod.GET, request -> {}, response -> {
streamingRestClient.get().uri(
"/api/traces/operations/stream?serviceName=pastry-details&operationName=GET /pastry&clientAddress=.*")
.exchange((request, response) -> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shutdownNow() interrupts the executor, but it does not explicitly close the active HTTP response. This test opens a long-lived SSE stream and blocks on bufferedReader.readLine(), while the server-side emitter is created with new SseEmitter(0L) in TraceSubscriptionManager.subscribe(), meaning there is no timeout. Could we retain the active response/stream and close it during teardown so the read loop terminates cleanly?

@dipak0000812 dipak0000812 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the SSE integration test changes and left two non-blocking comments regarding explicit cleanup of active SSE response streams during test teardown.

@Ashish-CodeJourney

Copy link
Copy Markdown
Author

Reviewed the SSE integration test changes and left two non-blocking comments regarding explicit cleanup of active SSE response streams during test teardown.

I am looking into that, Thanks.

The streaming RestClient used by the SSE integration tests had no read timeout, so reader threads could block until the server closed the stream. Give it a 5 second read timeout so the reader exits on its own.

Signed-off-by: Ashish Vaghela <[email protected]>
@Ashish-CodeJourney

Copy link
Copy Markdown
Author

Reviewed the SSE integration test changes and left two non-blocking comments regarding explicit cleanup of active SSE response streams during test teardown.

Thanks for the review, both points are valid. Teardown only shut down the executor, so the SSE reader thread stayed blocked on readLine() until the server-side emitter timed out. That is the case for TracingControllerIT in particular, since its emitter has no timeout.

@Ashish-CodeJourney

Copy link
Copy Markdown
Author

streamingRestClient.get().uri(
"/api/traces/operations/stream?serviceName=pastry-details&operationName=GET /pastry&clientAddress=.*")
.exchange((request, response) -> {

@dipak0000812 The streaming client now has a 5 second read timeout, so each reader exits on its own. The four SSE call sites are unchanged they all use this client.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: migrate webapp ITs from TestRestTemplate to RestTestClient

2 participants