pam/gdmmodel-test: Fix flaky StartAuthentication synchronization - #1598
Draft
adombeck wants to merge 1 commit into
Draft
pam/gdmmodel-test: Fix flaky StartAuthentication synchronization#1598adombeck wants to merge 1 commit into
adombeck wants to merge 1 commit into
Conversation
The gdm conversation handler test used an unbuffered startAuthRequested channel to coordinate StartAuthentication events with the goroutines that inject the next authentication data. Each StartAuthentication event pushed a token via an asynchronous goroutine, while waitForAuthenticationStarted consumed tokens (blocking) and consumeAuthenticationStartedEvents (on stopAuthentication) drained a spurious pending token with a non-blocking select. Because the producer was asynchronous, consumeAuthenticationStartedEvents could run before the spurious token had actually landed in the channel, hit its default branch, and skip the drain. The stale token would then be consumed later by the *next* waitForAuthenticationStarted, causing the following auth data to be injected too early. In the "Changing password fails when same as old password" case this made the second password go through a real IsAuthenticated call (dummy returns Next) instead of the local new-password quality check (Retry, "same as the old one"), so the expected second authEvent never arrived and the test timed out. Replace the channel with a counter guarded by a sync.Cond sharing the handler mutex. The counter is now incremented synchronously while the StartAuthentication event is handled, so a later stopAuthentication always observes the pending start and drains it deterministically. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1598 +/- ##
==========================================
+ Coverage 87.13% 87.63% +0.49%
==========================================
Files 119 98 -21
Lines 7907 6745 -1162
Branches 111 111
==========================================
- Hits 6890 5911 -979
+ Misses 961 778 -183
Partials 56 56 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Important
Don't review yet, I'm just creating this draft PR to run the flaky test a few times. I didn't review the changes myself yet!
The gdm conversation handler test used an unbuffered startAuthRequested channel to coordinate StartAuthentication events with the goroutines that inject the next authentication data. Each StartAuthentication event pushed a token via an asynchronous goroutine, while waitForAuthenticationStarted consumed tokens (blocking) and consumeAuthenticationStartedEvents (on stopAuthentication) drained a spurious pending token with a non-blocking select.
Because the producer was asynchronous, consumeAuthenticationStartedEvents could run before the spurious token had actually landed in the channel, hit its default branch, and skip the drain. The stale token would then be consumed later by the next waitForAuthenticationStarted, causing the following auth data to be injected too early. In the "Changing password fails when same as old password" case this made the second password go through a real IsAuthenticated call (dummy returns Next) instead of the local new-password quality check (Retry, "same as the old one"), so the expected second authEvent never arrived and the test timed out.
Replace the channel with a counter guarded by a sync.Cond sharing the handler mutex. The counter is now incremented synchronously while the StartAuthentication event is handled, so a later stopAuthentication always observes the pending start and drains it deterministically.