github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/replica_consistency_test.go (about)

     1  // Copyright 2019 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
    12  
    13  import (
    14  	"context"
    15  	"testing"
    16  
    17  	"github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval"
    18  	"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb"
    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/cockroach/pkg/util/uuid"
    24  	"github.com/stretchr/testify/require"
    25  )
    26  
    27  func TestReplicaChecksumVersion(t *testing.T) {
    28  	defer leaktest.AfterTest(t)()
    29  
    30  	ctx := context.Background()
    31  	tc := testContext{}
    32  	stopper := stop.NewStopper()
    33  	defer stopper.Stop(ctx)
    34  	tc.Start(t, stopper)
    35  
    36  	testutils.RunTrueAndFalse(t, "matchingVersion", func(t *testing.T, matchingVersion bool) {
    37  		cc := kvserverpb.ComputeChecksum{
    38  			ChecksumID: uuid.FastMakeV4(),
    39  			Mode:       roachpb.ChecksumMode_CHECK_FULL,
    40  		}
    41  		if matchingVersion {
    42  			cc.Version = batcheval.ReplicaChecksumVersion
    43  		} else {
    44  			cc.Version = 1
    45  		}
    46  		tc.repl.computeChecksumPostApply(ctx, cc)
    47  		rc, err := tc.repl.getChecksum(ctx, cc.ChecksumID)
    48  		if !matchingVersion {
    49  			if !testutils.IsError(err, "no checksum found") {
    50  				t.Fatal(err)
    51  			}
    52  			require.Nil(t, rc.Checksum)
    53  		} else {
    54  			require.NoError(t, err)
    55  			require.NotNil(t, rc.Checksum)
    56  		}
    57  	})
    58  }