Skip to content

Commit

Permalink
kvserver: fix testing code that was accidentally in prod
Browse files Browse the repository at this point in the history
In 65df6fc, I added code intended to
catch racy uses of manual replication in tests. Unfortunately, the
condition I used to check whether we were in a test was always true
(the return of `TestingKnobs()` is never nil).

I looked around for a better way to test whether we're running in
a test and it's not that straightforward, but we do get to find
out whether running as part of nightly stress, and that seems
like a good enough context in which to enable these checks.

Fixes #57863.

Release note: None
  • Loading branch information
tbg committed Dec 16, 2020
1 parent de1ea0c commit a8612df
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/kv/kvserver/replica_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/rpc/nodedialer"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/storage"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/contextutil"
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
Expand Down Expand Up @@ -929,10 +930,10 @@ func (r *Replica) ChangeReplicas(
return nil, errors.Errorf("%s: the current RangeDescriptor must not be nil", r)
}

// If there are testing knobs, we're definitely in a test.
// Try to catch tests that use manual replication while the
// replication queue is active. Such tests are often flaky.
if knobs := r.store.TestingKnobs(); knobs != nil &&
// If in testing (for lack of a better mechanism, we restrict to race builds),
// try to catch tests that use manual replication while the replication queue
// is active. Such tests are often flaky.
if knobs := r.store.TestingKnobs(); util.RaceEnabled &&
!knobs.DisableReplicateQueue &&
!knobs.AllowUnsynchronizedReplicationChanges {
bq := r.store.replicateQueue.baseQueue
Expand Down

0 comments on commit a8612df

Please sign in to comment.