github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/replicate_test.go (about) 1 // Copyright 2016 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package kvserver_test 12 13 import ( 14 "context" 15 "testing" 16 17 "github.com/cockroachdb/cockroach/pkg/kv" 18 "github.com/cockroachdb/cockroach/pkg/kv/kvserver" 19 "github.com/cockroachdb/cockroach/pkg/roachpb" 20 "github.com/cockroachdb/cockroach/pkg/testutils" 21 "github.com/cockroachdb/cockroach/pkg/util/leaktest" 22 "github.com/cockroachdb/cockroach/pkg/util/stop" 23 "github.com/cockroachdb/errors" 24 ) 25 26 func TestEagerReplication(t *testing.T) { 27 defer leaktest.AfterTest(t)() 28 29 ctx := context.Background() 30 storeCfg := kvserver.TestStoreConfig(nil /* clock */) 31 // Disable the replica scanner so that we rely on the eager replication code 32 // path that occurs after splits. 33 storeCfg.TestingKnobs.DisableScanner = true 34 35 stopper := stop.NewStopper() 36 defer stopper.Stop(ctx) 37 store := createTestStoreWithConfig(t, stopper, storeCfg) 38 39 // After bootstrap, all of the system ranges should be present in replicate 40 // queue purgatory (because we only have a single store in the test and thus 41 // replication cannot succeed). 42 purgatoryStartCount := store.ReplicateQueuePurgatoryLength() 43 44 t.Logf("purgatory start count is %d", purgatoryStartCount) 45 // Perform a split and check that there's one more range in the purgatory. 46 47 key := roachpb.Key("a") 48 args := adminSplitArgs(key) 49 _, pErr := kv.SendWrapped(ctx, store.TestSender(), args) 50 if pErr != nil { 51 t.Fatal(pErr) 52 } 53 54 // The addition of replicas to the replicateQueue after a split 55 // occurs happens after the update of the descriptors in meta2 56 // leaving a tiny window of time in which the newly split replica 57 // will not have been added to purgatory. Thus we loop. 58 testutils.SucceedsSoon(t, func() error { 59 expected := purgatoryStartCount + 1 60 if n := store.ReplicateQueuePurgatoryLength(); expected != n { 61 return errors.Errorf("expected %d replicas in purgatory, but found %d", expected, n) 62 } 63 return nil 64 }) 65 }