Skip to content

Commit 676f28f

Browse files
craig[bot]tbg
andcommitted
148593: storage_api: don't check raft status in test r=tbg a=tbg This seems unrelated to the test. We don't actually guarantee that a single node raft group can't transition through StateCandidate; clearly it's possible. Via backports: Closes #148564. Epic: none 148656: kvserver: deflake TestReplicateQueueUpReplicateOddVoters r=tbg a=tbg Fixes #147566. Epic: none Co-authored-by: Tobias Grieger <[email protected]>
3 parents ea594f0 + a66e96c + 4ec3691 commit 676f28f

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
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

pkg/server/storage_api/ranges_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/cockroachdb/cockroach/pkg/keys"
1515
"github.com/cockroachdb/cockroach/pkg/kv/kvserver"
1616
"github.com/cockroachdb/cockroach/pkg/roachpb"
17-
"github.com/cockroachdb/cockroach/pkg/server"
1817
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
1918
"github.com/cockroachdb/cockroach/pkg/server/srvtestutils"
2019
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
@@ -56,9 +55,6 @@ func TestRangesResponse(t *testing.T) {
5655
for _, ri := range response.Ranges {
5756
// Do some simple validation based on the fact that this is a
5857
// single-node cluster.
59-
if ri.RaftState.State != "StateLeader" && ri.RaftState.State != server.RaftStateDormant {
60-
t.Errorf("expected to be Raft leader or dormant, but was '%s'", ri.RaftState.State)
61-
}
6258
expReplica := roachpb.ReplicaDescriptor{
6359
NodeID: 1,
6460
StoreID: 1,

0 commit comments

Comments
 (0)