SIGN IN SIGN UP

test(membership): fix flaky backoff-expiry test that reddened unrelated PRs

TestBackgroundFetchRetriesAfterBackoffExpiry used two barriers that do
not actually gate the state it asserts on, so it failed intermittently
in CI on PRs that do not touch this package (#163, #166, #169).

Both barriers were false:

  - fakeMemberAPI records a call on *entry*, but backgroundFetch writes
    lastFailed only after the API call returns. Backdating lastFailed
    after waitForCallCount(1) therefore raced the manager's own write
    and got clobbered, leaving the backoff live so the retry never
    fired: "timed out waiting for 2 API calls".

  - EnsureFresh calls pushSnapshot synchronously on the caller's
    goroutine, so waitForPush(sink, 2) was satisfied by the test's own
    second EnsureFresh rather than by the background fetch. The
    lastFailed assertion then ran while that fetch was still in flight:
    "lastFailed not cleared by a successful fetch".

Replace both with waitUntil, which polls the manager state under its own
lock. Add an optional post-call delay to fakeMemberAPI and use it here,
so the slow-API interleaving that used to be a rare race is now the
test's default path.

Verified: with the 50ms delay the old test failed 5/5; the new one
passes 20/20 under -race, and still fails as intended when
`delete(m.lastFailed, channelID)` is removed from manager.go.
G
Grant Ammons committed
8eaeba9d94900c37c5de5cf724bb85ead1e62a99
Parent: c782404