Repository navigation
test(ktor): wait for a route's failure in real time - #130
Merged
Merged
Conversation
TestBalloon runs tests in a TestScope, on a virtual clock. The test waited for the failure, which comes from a real thread, with withTimeout(10.seconds) on that clock. Once the test had nothing else scheduled, the virtual clock jumped ahead and the timeout fired at once, unless the failure had already arrived. That made the test flaky on a slow runner. Wait on Dispatchers.Default, so the timeout is 10 real seconds, as GrpcServerTest does.
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
KtorServiceTest's "a route can fail the service's scope, which stops the application" test is flaky.TestBalloon runs every test in a
TestScopeby default (TestSession.DefaultConfigurationcalls.testScope(true)), so delays and timeouts run on a virtual clock. The test waited for the route's failure withwithTimeout(10.seconds) { failure.await() }. That failure is thrown on a real thread (Dispatchers.Default). If the test coroutine had nothing else scheduled when it started waiting, the virtual clock jumped ten seconds ahead and the timeout fired at once. The test passed only when the failure had already arrived, which a slow CI runner can miss.The wait now runs on
Dispatchers.Default, so its timeout is ten real seconds.GrpcServerTestalready waits this way.Testing
:boot-server-http-ktor:testpasses five times in a row.error("died"), the previous wait fails on both CIO and Netty with theTimeoutCancellationExceptionseen in CI, and the new wait passes.