fix: RekeyTest stability#129
Merged
Merged
Conversation
Use Kotlin StateFlow for rekey count so we do not need to use delay. Provide a way to pass a CoroutineDispatcher to the state machine so it can be on the same clock as the tests. This lets us advance time virtually in a test.
Contributor
There was a problem hiding this comment.
Pull request overview
Improves the stability of rekey-related tests by making rekey observation deterministic (via StateFlow) and allowing SshConnection’s state machine to run on an injected dispatcher so tests can use the same virtual clock.
Changes:
- Replace
FakeSshServer.rekeyCountinteger polling/delays with aStateFlowthat tests can await. - Update
RekeyTestto useStandardTestDispatcher(testScheduler)and await rekey events rather than sleeping. - Add
stateMachineDispatcherinjection toSshConnectionand adjust dispatcher lifecycle handling inclose().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
sshlib/src/test/kotlin/org/connectbot/sshlib/client/RekeyTest.kt |
Removes delay-based polling and switches to awaiting a rekey StateFlow while using a test dispatcher/scheduler. |
sshlib/src/test/kotlin/org/connectbot/sshlib/client/FakeSshServer.kt |
Exposes rekey count as a StateFlow and allows launching server coroutines on a provided coroutine context. |
sshlib/src/main/kotlin/org/connectbot/sshlib/client/SshConnection.kt |
Introduces injectable stateMachineDispatcher and changes shutdown behavior around dispatcher closing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e7ffe79 to
2f1e1fb
Compare
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.
Use Kotlin StateFlow for rekey count so we do not need to use delay. Provide a way to pass a CoroutineDispatcher to the state machine so it can be on the same clock as the tests. This lets us advance time virtually in a test.