Skip to content

Commit

Permalink
server,kvserver: use real Descriptor value in test
Browse files Browse the repository at this point in the history
The test would hit an assertion in the leasemanager otherwise.

Release note: None
  • Loading branch information
ajwerner committed May 12, 2020
1 parent b2dfb7f commit 9bf0ceb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
5 changes: 3 additions & 2 deletions pkg/kv/kvserver/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/gossip"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
Expand Down Expand Up @@ -211,10 +212,10 @@ func TestGossipAfterAbortOfSystemConfigTransactionAfterFailureDueToIntents(t *te
txB := db.NewTxn(ctx, "b")

require.NoError(t, txA.SetSystemConfigTrigger())
require.NoError(t, txA.Put(ctx, keys.SystemSQLCodec.DescMetadataKey(1000), "foo"))
require.NoError(t, txA.Put(ctx, keys.SystemSQLCodec.DescMetadataKey(1000), &sqlbase.Descriptor{}))

require.NoError(t, txB.SetSystemConfigTrigger())
require.NoError(t, txB.Put(ctx, keys.SystemSQLCodec.DescMetadataKey(2000), "bar"))
require.NoError(t, txB.Put(ctx, keys.SystemSQLCodec.DescMetadataKey(2000), &sqlbase.Descriptor{}))

const someTime = 10 * time.Millisecond
clearNotifictions := func(ch <-chan struct{}) {
Expand Down
25 changes: 17 additions & 8 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,14 +540,17 @@ func TestMultiRangeScanWithPagination(t *testing.T) {
func TestSystemConfigGossip(t *testing.T) {
defer leaktest.AfterTest(t)()

ctx := context.Background()
s, _, kvDB := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop(context.TODO())
defer s.Stopper().Stop(ctx)
ts := s.(*TestServer)
ctx := context.TODO()

key := sqlbase.MakeDescMetadataKey(keys.SystemSQLCodec, keys.MaxReservedDescID)
valAt := func(i int) *sqlbase.DatabaseDescriptor {
return &sqlbase.DatabaseDescriptor{Name: "foo", ID: sqlbase.ID(i)}
valAt := func(i int) *sqlbase.Descriptor {
return sqlbase.WrapDescriptor(&sqlbase.DatabaseDescriptor{
ID: sqlbase.ID(i),
Name: "foo",
})
}

// Register a callback for gossip updates.
Expand Down Expand Up @@ -598,12 +601,18 @@ func TestSystemConfigGossip(t *testing.T) {
}

// Make sure the returned value is valAt(2).
got := new(sqlbase.DatabaseDescriptor)
if err := val.GetProto(got); err != nil {
var got sqlbase.Descriptor
if err := val.GetProto(&got); err != nil {
return err
}
if expected := valAt(2); !reflect.DeepEqual(got, expected) {
return errors.Errorf("mismatch: expected %+v, got %+v", *expected, *got)

expected := valAt(2).GetDatabase()
db := got.GetDatabase()
if db == nil {
panic(errors.Errorf("found nil database: %v", got))
}
if !reflect.DeepEqual(*db, *expected) {
panic(errors.Errorf("mismatch: expected %+v, got %+v", *expected, *db))
}
return nil
})
Expand Down

0 comments on commit 9bf0ceb

Please sign in to comment.