Skip to content

fix: RekeyTest stability#129

Merged
kruton merged 1 commit into
mainfrom
rekey-test-fix
Apr 29, 2026
Merged

fix: RekeyTest stability#129
kruton merged 1 commit into
mainfrom
rekey-test-fix

Conversation

@kruton
Copy link
Copy Markdown
Member

@kruton kruton commented Apr 29, 2026

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.

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.
Copilot AI review requested due to automatic review settings April 29, 2026 17:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.rekeyCount integer polling/delays with a StateFlow that tests can await.
  • Update RekeyTest to use StandardTestDispatcher(testScheduler) and await rekey events rather than sleeping.
  • Add stateMachineDispatcher injection to SshConnection and adjust dispatcher lifecycle handling in close().

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.

Comment thread sshlib/src/test/kotlin/org/connectbot/sshlib/client/RekeyTest.kt
Comment thread sshlib/src/test/kotlin/org/connectbot/sshlib/client/RekeyTest.kt
Comment thread sshlib/src/test/kotlin/org/connectbot/sshlib/client/RekeyTest.kt
Comment thread sshlib/src/test/kotlin/org/connectbot/sshlib/client/RekeyTest.kt
Comment thread sshlib/src/test/kotlin/org/connectbot/sshlib/client/FakeSshServer.kt Outdated
Comment thread sshlib/src/test/kotlin/org/connectbot/sshlib/client/FakeSshServer.kt Outdated
Comment thread sshlib/src/main/kotlin/org/connectbot/sshlib/client/SshConnection.kt Outdated
Comment thread sshlib/src/test/kotlin/org/connectbot/sshlib/client/RekeyTest.kt
@kruton kruton force-pushed the rekey-test-fix branch 3 times, most recently from e7ffe79 to 2f1e1fb Compare April 29, 2026 17:57
@kruton kruton merged commit f217449 into main Apr 29, 2026
10 checks passed
@kruton kruton deleted the rekey-test-fix branch April 29, 2026 18:03
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.

2 participants