Cause: TestPartnersFromTheFeed's first Partners() call (to see that
nothing is listed before a fetch) starts a background refreshPartners,
since no list was ever fetched. The test helper fetchPartnersNow called
refreshPartners directly, skipping the partnerFetches guard that
Partners and PartnersNow use, so the two fetches ran together. When the
background fetch read the full list and stored it after the helper's
fetch of the emptied list, the test saw acme,regioned. magpie itself
never runs two fetches at once (only Partners and PartnersNow start one,
both through the guard), so this is a test-only race, not a product
bug. resetPartners also cleared the guard while a fetch could still be
running, which let a late fetch store into the next test's state.
Fix: fetchPartnersNow waits for a running fetch and claims the guard
before fetching (claimPartnerFetch), and resetPartners waits for a
running fetch before it forgets the list.
New test TestPartnersFetchedLastIsHeld: the fetch Partners starts reads
the full list and answers late; the list is emptied and
fetchPartnersNow runs; the empty list must be what is held. With the old
fetchPartnersNow it fails 5/5 ("partners after the list emptied =
acme"). The CI failure itself was reproduced by injecting the delay: a
300ms first response from the feed server and a 400ms pause before the
check made TestPartnersFromTheFeed fail with CI's exact message on the
old code; with the fix it passes 5/5 under the same injection.
Run (temp HOME, Go caches pinned):
- go test -tags nogui -race -count=20 -cpu 1,2 -shuffle=on -run Partner ./internal/provider/: ok
- go test -tags nogui ./internal/provider/...: ok
- gofmt -l internal/provider/: nothing
- go vet -tags nogui ./internal/provider/ (darwin, GOOS=linux, GOOS=windows): ok