Skip to content

pam/gdmmodel-test: Fix flaky StartAuthentication synchronization - #1598

Draft
adombeck wants to merge 1 commit into
mainfrom
fix-gdm-flaky-startauth-race
Draft

pam/gdmmodel-test: Fix flaky StartAuthentication synchronization#1598
adombeck wants to merge 1 commit into
mainfrom
fix-gdm-flaky-startauth-race

Conversation

@adombeck

Copy link
Copy Markdown
Contributor

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.

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

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.63%. Comparing base (50490bb) to head (a634231).
⚠️ Report is 5 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant