Skip to content

Conversation

@hydrationn
Copy link

This PR removes Thread.sleep from async tests in DefaultAsyncServerResponseTests
and replaces it with a non-blocking CompletableFuture pattern. This makes the
test more deterministic and avoids timing-based flakiness.

🔍 What was changed

  • Removed Thread.sleep(500) inside CompletableFuture.supplyAsync
  • Replaced it with a non-blocking test pattern:
    • Created an incomplete CompletableFuture
    • Completed it asynchronously using new Thread(() -> future.complete(...))
  • This makes the test more deterministic and avoids relying on timing-based behavior

💡 Why this change

Using Thread.sleep in tests is generally discouraged because:

  • It increases test execution time
  • It may lead to unstable test results depending on system timing
  • It does not reflect real asynchronous behavior

The updated approach ensures:

  • Faster test execution
  • More reliable async behavior
  • Clearer test intent

📌 Notes

No functional changes were made to production code.
This update improves the internal test quality and stability.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants