Skip to content

Commit

Permalink
Merge pull request #113748 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-23.1-113744

release-23.1: kvserver: deflake `TestReplicaCircuitBreaker_ExemptRequests`
  • Loading branch information
erikgrinaker authored Nov 7, 2023
2 parents 2962ac8 + 6d0a42a commit 92acbbc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/kv/kvserver/client_replica_circuit_breaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,12 @@ func TestReplicaCircuitBreaker_ExemptRequests(t *testing.T) {
})
}

// Restore the breaker via the probe.
// Restore the breaker via the probe, and wait for any pending (re)proposals
// from previous tests to be flushed.
resumeHeartbeats()
tc.SetProbeEnabled(n1, true)
tc.UntripsSoon(t, tc.Write, n1)
tc.WaitForProposals(t, n1)

// Lose quorum (liveness stays intact).
tc.SetSlowThreshold(10 * time.Millisecond)
Expand Down Expand Up @@ -889,6 +891,19 @@ func (cbt *circuitBreakerTest) UntripsSoon(t *testing.T, method func(idx int) er
})
}

func (cbt *circuitBreakerTest) WaitForProposals(t *testing.T, idx int) {
t.Helper()
testutils.SucceedsSoon(t, func() error {
t.Helper()

repl := cbt.repls[idx].Replica
if n := repl.NumPendingProposals(); n > 0 {
return errors.Errorf("%d pending proposals", n)
}
return nil
})
}

func (cbt *circuitBreakerTest) ExpireAllLeasesAndN1LivenessRecord(
t *testing.T, pauseHeartbeats bool,
) (undo func()) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/kv/kvserver/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ func (r *Replica) QuotaReleaseQueueLen() int {
return len(r.mu.quotaReleaseQueue)
}

func (r *Replica) NumPendingProposals() int {
r.mu.RLock()
defer r.mu.RUnlock()
return r.numPendingProposalsRLocked()
}

func (r *Replica) IsFollowerActiveSince(
ctx context.Context, followerID roachpb.ReplicaID, threshold time.Duration,
) bool {
Expand Down

0 comments on commit 92acbbc

Please sign in to comment.