Skip to content

[PM-36604] test: Fix flaky WatchServiceTests#2617

Merged
KatherineInCode merged 4 commits into
mainfrom
pm-36604/flaky-watchservice-test
May 18, 2026
Merged

[PM-36604] test: Fix flaky WatchServiceTests#2617
KatherineInCode merged 4 commits into
mainfrom
pm-36604/flaky-watchservice-test

Conversation

@KatherineInCode
Copy link
Copy Markdown
Contributor

@KatherineInCode KatherineInCode commented May 6, 2026

🎟️ Tracking

PM-36604

📔 Objective

Fixes three flaky tests in WatchServiceTests:

  1. syncWithWatch_shouldNotConnect_sendsNeedSetup — captures the application context inside block 2's closure rather than reading the shared mock property afterwards. A still-running syncCiphersTask from the first sync could overwrite updateApplicationContextReceivedApplicationContext between the resume() call and the assertion.
  2. syncWithWatch_vaultLocked_skipsCipherSync — replaces Task.sleep(10_000_000) with a deterministic barrier sync: after the locked event, a shouldConnect=false event triggers a .needSetup response (which short-circuits before decryptCiphers) and provides a reliable signal that the locked sync was fully processed with no extra decryption.
  3. syncWithWatch_vaultUnlocked_syncsAfterUnlock — replaces Task.sleep(10_000_000) + post-sleep assertion with an in-closure assertion on updateApplicationContextCallsCount. The locked sync returns early at the isVaultLocked guard without calling updateApplicationContext, so asserting callsCount == 1 inside the unlock callback is both correct and deterministic.

@KatherineInCode KatherineInCode added the ai-review-vnext Request a Claude code review using the vNext workflow label May 6, 2026
@github-actions github-actions Bot added app:password-manager Bitwarden Password Manager app context t:tech-debt Change Type - Tech debt labels May 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

Reviewed test-only changes to WatchServiceTests.swift that fix three flaky tests by removing fixed-duration Task.sleep calls and a TOCTOU race on a shared mock property. The fixes use deterministic patterns already established in the file: capturing values inside the callback closure, and using a subsequent event as a barrier sync that guarantees the prior event's task has been processed. Traced the production DefaultWatchService.syncWithWatch(userId:shouldConnect:isVaultLocked:) flow and confirmed the locked-branch early return (before updateApplicationContext) makes the test assumptions correct. The previously flagged experimental time-limit tests were removed in commit 0a5b6ae9 and are not present in the final diff.

Code Review Details

No findings.

@KatherineInCode KatherineInCode force-pushed the pm-36604/flaky-watchservice-test branch from b45e20a to ca7a047 Compare May 6, 2026 15:02
@github-actions github-actions Bot removed the t:tech-debt Change Type - Tech debt label May 6, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.31%. Comparing base (d61c576) to head (e16f245).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2617   +/-   ##
=======================================
  Coverage   87.31%   87.31%           
=======================================
  Files        1912     1912           
  Lines      170379   170400   +21     
=======================================
+ Hits       148759   148779   +20     
- Misses      21620    21621    +1     

☔ View full report in Codecov by Sentry.
📢 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.

@KatherineInCode KatherineInCode marked this pull request as ready for review May 7, 2026 14:03
@KatherineInCode KatherineInCode requested review from a team and matt-livefront as code owners May 7, 2026 14:03
Comment thread BitwardenShared/Core/Platform/Services/WatchServiceTests.swift Outdated
@KatherineInCode KatherineInCode added the hold This shouldn't be merged yet label May 7, 2026
@github-actions github-actions Bot added the t:tech-debt Change Type - Tech debt label May 8, 2026
Comment thread BitwardenShared/Core/Platform/Services/WatchServiceTests.swift Outdated
@KatherineInCode KatherineInCode removed the hold This shouldn't be merged yet label May 11, 2026
@KatherineInCode KatherineInCode merged commit 5138e4c into main May 18, 2026
20 checks passed
@KatherineInCode KatherineInCode deleted the pm-36604/flaky-watchservice-test branch May 18, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review-vnext Request a Claude code review using the vNext workflow app:password-manager Bitwarden Password Manager app context t:tech-debt Change Type - Tech debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants