test: retry the Keychain store-wide reads that raced their own writes - #79
Merged
Merged
Conversation
main went red on macos-14: GetProviderNamesAsync_ReturnsDistinctProviders reported "Expected: 2, Actual: 0" after adding three credentials. The same commit passed that leg on the PR run minutes earlier, so it is timing, not a regression -- and not a consequence of the #55 owner-attribute change, which falls back to the prefix test when no owner is recorded. AddCredentialAsync confirms visibility via QuerySingleItem, an exact service+account query. ListCredentialsAsync and GetProviderNamesAsync go through QueryItems/QueryAllItemsForApp, a class-wide query filtered in memory. Being visible to one does not imply being visible to the other, which is exactly the mismatch #61 fixed for the libsecret Restore test. Fourteen reads in this file already used RetryHelper. Six did not, and any of them could have lost the same race; GetProviderNamesAsync was simply first. All six now retry, each on the condition the test then asserts rather than on something merely having appeared -- a count-only predicate is what let #61 through. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Fixes the red
main.What happened
The post-merge run of #78 failed on
test (macos-14):The same commit passed that same leg on the PR run minutes earlier, so it is timing rather than a regression. It is also not a consequence of the #55 owner-attribute change: when no owner is recorded
IsOwnedByThisAppfalls back to the prefix test, so filtering cannot zero the result.Root cause — the same mismatch as #61
AddCredentialAsyncconfirms its write is visible viaQuerySingleItem, an exact service+account query.ListCredentialsAsyncandGetProviderNamesAsyncgo throughQueryItems/QueryAllItemsForApp, a class-wide query filtered in memory. Visibility to one does not imply visibility to the other, so a read on the second path can legitimately see nothing straight after a write confirmed on the first.That is precisely the mismatch #61 fixed for the libsecret Restore test. Same shape, different file.
The fix, and why six tests rather than one
Fourteen reads in
KeychainCredentialManagerTestsalready usedRetryHelper. Six did not —GetProviderNamesAsyncwas simply the one that lost the race first, and the other five were equally exposed. All six now retry.Each predicate matches what the test then asserts, not merely that something appeared:
ListCredentialsAsync_ReturnsAddedCredentialr.Any(c => c.AccountId == accountId)ListCredentialsAsync_FiltersByProviderr.Count() == 1per providerGetCredentialByIdAsync_DoesNotMutateSelectionr.Count() == 2 && r.Any(c => c.IsSelected)DeleteCredentialAsync_RemovesCredential!r.Any()GetProviderNamesAsync_ReturnsDistinctProvidersr.Count() == 2ListCredentialsAsync_IncludesDisplayFields_FromSummaryProviderr.Count() == 1A count-only predicate guarding a content assertion is exactly what let #61 through, so the third row waits on the selection being visible too, not just on two rows existing.
Verification
Build clean, 416 tests locally. The macOS legs are the ones that matter here and only CI runs them — worth watching
test (macos-14)andtest (macos-15)specifically on this PR, and onmainafter merge, since a timing fix cannot be proven by a single green run.🤖 Generated with Claude Code