Skip to content

Commit 4ec3691

Browse files
committed
kvserver: deflake TestReplicateQueueUpReplicateOddVoters
Fixes #147566. Epic: none
1 parent 32b9329 commit 4ec3691

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

pkg/kv/kvserver/replicate_queue_test.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/allocatorimpl"
3232
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/plan"
3333
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb"
34+
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness"
3435
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb"
3536
"github.com/cockroachdb/cockroach/pkg/raft/raftpb"
3637
"github.com/cockroachdb/cockroach/pkg/raft/tracker"
@@ -399,29 +400,36 @@ func TestReplicateQueueUpReplicateOddVoters(t *testing.T) {
399400

400401
tc.AddAndStartServer(t, base.TestServerArgs{})
401402

402-
if err := tc.Servers[0].GetStores().(*kvserver.Stores).VisitStores(func(s *kvserver.Store) error {
403-
return s.ForceReplicationScanAndProcess()
404-
}); err != nil {
405-
t.Fatal(err)
406-
}
407-
// After the initial splits have been performed, all of the resulting ranges
408-
// should be present in replicate queue purgatory (because we only have a
409-
// single store in the test and thus replication cannot succeed).
410-
expected, err := tc.Servers[0].ExpectedInitialRangeCount()
411-
if err != nil {
412-
t.Fatal(err)
413-
}
403+
// NB: the following usually succeeds on the first attempt. However, it's
404+
// also possible for s2 to initially enter "suspect" status, in which case
405+
// there is a default 30s timeout (which we lower below) and we may need to
406+
// retry a few times as the replicate queue won't add replicas to purgatory
407+
// unless s2 is available as a replication target.
408+
liveness.TimeAfterNodeSuspect.Override(context.Background(), &tc.Servers[0].ClusterSettings().SV, time.Second)
409+
testutils.SucceedsSoon(t, func() error {
410+
if err := tc.Servers[0].GetStores().(*kvserver.Stores).VisitStores(func(s *kvserver.Store) error {
411+
return s.ForceReplicationScanAndProcess()
412+
}); err != nil {
413+
t.Fatal(err)
414+
}
415+
// After the initial splits have been performed, all of the resulting ranges
416+
// should be present in replicate queue purgatory (because we only have a
417+
// single store in the test and thus replication cannot succeed).
418+
expected, err := tc.Servers[0].ExpectedInitialRangeCount()
419+
require.NoError(t, err)
420+
421+
var store *kvserver.Store
422+
_ = tc.Servers[0].GetStores().(*kvserver.Stores).VisitStores(func(s *kvserver.Store) error {
423+
store = s
424+
return nil
425+
})
414426

415-
var store *kvserver.Store
416-
_ = tc.Servers[0].GetStores().(*kvserver.Stores).VisitStores(func(s *kvserver.Store) error {
417-
store = s
427+
if n := store.ReplicateQueuePurgatoryLength(); expected != n {
428+
return errors.Errorf("expected %d replicas in purgatory, but found %d", expected, n)
429+
}
418430
return nil
419431
})
420432

421-
if n := store.ReplicateQueuePurgatoryLength(); expected != n {
422-
t.Fatalf("expected %d replicas in purgatory, but found %d", expected, n)
423-
}
424-
425433
tc.AddAndStartServer(t, base.TestServerArgs{})
426434

427435
// Now wait until the replicas have been up-replicated to the

0 commit comments

Comments
 (0)