Skip to content

[tests] Fix flaky DeskCase_83099_InmutableDictionary keychain test#25251

Open
rolfbjarne wants to merge 4 commits intomainfrom
dev/rolf/fix-flaky-keychain-test
Open

[tests] Fix flaky DeskCase_83099_InmutableDictionary keychain test#25251
rolfbjarne wants to merge 4 commits intomainfrom
dev/rolf/fix-flaky-keychain-test

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

Three changes to eliminate intermittent InvalidRecord failures in DeskCase_83099_InmutableDictionary:

  1. Unique keychain identity per process — server name is now Test1-{PID} to avoid cross-process conflicts on shared CI agents.

  2. Removed LAContext from search/delete records — the LAContext with InteractionNotAllowed was being attached to query and remove operations via InitSecRecord/CreateSecRecord. This is unnecessary for plain internet passwords and is a plausible cause of the intermittent InvalidRecord errors. Helper methods now use a minimal SecRecord for lookups.

  3. Handle unexpected query status codes — the old SaveUserPassword only handled ItemNotFound (add path) and Success (update path). Any other status like InvalidRecord silently returned false. The restructured logic uses Success → update, else → force-remove + add.

Fixes #25222

Three changes to eliminate intermittent InvalidRecord failures:

1. Use a process-unique server name (Test1-{PID}) to avoid cross-process
   keychain conflicts on shared CI agents.

2. Stop attaching LAContext with InteractionNotAllowed to search/delete
   records. The LAContext can cause intermittent InvalidRecord errors on
   some macOS keychain states. Plain internet passwords don't require
   biometric auth, so the LAContext is unnecessary for these operations.

3. Handle unexpected query status codes (e.g. InvalidRecord) by falling
   through to the add path instead of silently returning false. The
   previous code only handled ItemNotFound and Success, leaving any
   other query result as an unrecoverable failure.

Fixes #25222

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 2 commits April 27, 2026 19:12
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne marked this pull request as ready for review April 28, 2026 09:07
Copilot AI review requested due to automatic review settings April 28, 2026 09:07
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

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

Fixes flakiness in the DeskCase_83099_InmutableDictionary keychain test by reducing cross-run keychain collisions and making keychain save/update logic more resilient to unexpected keychain states.

Changes:

  • Make keychain identity unique per process by including the PID in the server name (and clean up legacy "Test1" entries).
  • Stop attaching LAContext to keychain query/remove operations by using a minimal SecRecord for lookups/deletes.
  • Restructure save logic to handle unexpected query status codes by force-removing and re-adding entries when needed.

Comment on lines +352 to +360
// Create a minimal SecRecord for keychain queries and deletes (no LAContext).
// Using LAContext with InteractionNotAllowed on search records can cause
// intermittent InvalidRecord errors on some macOS keychain states.
static SecRecord CreateKeychainSearchRecord (string server, string username)
{
return new SecRecord (SecKind.InternetPassword) {
Server = server,
Account = username.ToLower (),
};
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

CreateKeychainSearchRecord bypasses InitSecRecord, which is where the macOS-specific CI ignore for macOS 11 + Xcode 12.2.x is enforced ("Skip on macOS 11.* because it hangs"). With this change, DeskCase_83099_InmutableDictionary will no longer hit that guard and may hang in the exact configuration the guard was added for. Consider factoring the macOS hang check out of InitSecRecord (or duplicating just that check) and invoking it from these new keychain helpers (or at the start of DeskCase_83099_InmutableDictionary) while still avoiding LAContext.

Copilot uses AI. Check for mistakes.
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

The new helper methods bypass InitSecRecord (intentionally, to avoid
LAContext), but that also skipped the macOS 11.* CI hang guard. Add
the guard directly to the test method.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rolfbjarne rolfbjarne enabled auto-merge (squash) April 29, 2026 08:43
@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #e77faa8] Build passed (Build packages) ✅

Pipeline on Agent
Hash: e77faa873a230ed37ef1df49a61a62574876c1e3 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #e77faa8] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: e77faa873a230ed37ef1df49a61a62574876c1e3 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: e77faa873a230ed37ef1df49a61a62574876c1e3 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #e77faa8] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: e77faa873a230ed37ef1df49a61a62574876c1e3 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🚀 [CI Build #e77faa8] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 156 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 12 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: e77faa873a230ed37ef1df49a61a62574876c1e3 [PR build]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI Postmortem] Flaky: MonoTouchFixtures.Security.RecordTest.DeskCase_83099_InmutableDictionary

4 participants