From e7db71c16e70256b9d440ca63fa2c289b94ae483 Mon Sep 17 00:00:00 2001 From: Felipe Fumero Date: Thu, 29 Oct 2026 15:55:55 -0600 Subject: [PATCH] test(b2): make the reauth waiter test deterministic The fake b2_authorize_account handler held the leader's reauthorization until the leader was cancelled, then still answered it with success and the expired token. If that response beat the client's cancellation, blazer correctly recorded a successful refresh with the stale token, the waiter reused it, and the test failed with 401 expired (seen once in CI). Never answer the leader's reauthorization while the test runs; release it at cleanup, which runs before the recording server's own cleanup. The leader now always ends through its cancelled context, and the R4 break (ignoring leaderContextExpired) fails the test on every run. Closes #237 --- b2/bucket_mapping_edges_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/b2/bucket_mapping_edges_test.go b/b2/bucket_mapping_edges_test.go index 139c0c23..752eccb3 100644 --- a/b2/bucket_mapping_edges_test.go +++ b/b2/bucket_mapping_edges_test.go @@ -59,12 +59,19 @@ func TestMappingReauthWaiterSurvivesCancelledLeader(t *testing.T) { defer cancelLeader() srv := b2wiretest.New(t) leaderAuthorizing := make(chan struct{}) + // The leader's reauthorization never gets an answer while the test runs, so + // the leader can only end through its cancelled context. Answering it after + // the cancel would race: a stale token could count as a successful refresh. + // Registered after b2wiretest.New, so it runs before the server's cleanup, + // which waits for this handler to return. + releaseLeaderAuth := make(chan struct{}) + t.Cleanup(func() { close(releaseLeaderAuth) }) var authCalls atomic.Int64 srv.Handle("b2_authorize_account", func(b2wiretest.Request) b2wiretest.Response { call := authCalls.Add(1) if call == 2 { close(leaderAuthorizing) - <-leaderCtx.Done() + <-releaseLeaderAuth } body := fmt.Sprintf(updateAuthJSON, srv.URL()) if call > 2 {