Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
hihihuhu committed Mar 30, 2023
1 parent 9cf179e commit dab3f0b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions infoschema/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func (h *InfoCache) getSchemaByTimestampNoLock(ts uint64) (InfoSchema, bool) {
}
if ts >= uint64(is.timestamp) {
// found the largest version before the given ts
return is.infoschema, false
return is.infoschema, true
}
}

logutil.BgLogger().Debug("SCHEMA CACHE no schema found")
return nil, true
return nil, false
}

// GetByVersion gets the information schema based on schemaVersion. Returns nil if it is not loaded.
Expand Down
10 changes: 7 additions & 3 deletions infoschema/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func TestInsert(t *testing.T) {
ic.Insert(is5, 5)
require.Equal(t, is5, ic.GetByVersion(5))
require.Equal(t, is2, ic.GetByVersion(2))
require.Equal(t, is2, ic.GetBySnapshotTS(2))
// there is a gap in schema cache, so don't use this version
require.Nil(t, ic.GetBySnapshotTS(2))
require.Equal(t, is5, ic.GetBySnapshotTS(10))

// older
Expand All @@ -59,7 +60,9 @@ func TestInsert(t *testing.T) {
require.Equal(t, is5, ic.GetByVersion(5))
require.Equal(t, is2, ic.GetByVersion(2))
require.Nil(t, ic.GetByVersion(0))
require.Equal(t, is2, ic.GetBySnapshotTS(2))
// there is a gap in schema cache, so don't use this version
require.Nil(t, ic.GetBySnapshotTS(2))
require.Equal(t, is5, ic.GetBySnapshotTS(5))
require.Equal(t, is6, ic.GetBySnapshotTS(10))

// replace 2, drop 2
Expand Down Expand Up @@ -145,7 +148,8 @@ func TestGetByTimestamp(t *testing.T) {
ic.Insert(is3, 3)
require.Equal(t, is3, ic.GetLatest())
require.Nil(t, ic.GetBySnapshotTS(0))
require.Equal(t, is1, ic.GetBySnapshotTS(2))
// there is a gap, no schema returned for ts 2
require.Nil(t, ic.GetBySnapshotTS(2))
require.Equal(t, is3, ic.GetBySnapshotTS(3))
require.Equal(t, is3, ic.GetBySnapshotTS(4))

Expand Down
8 changes: 4 additions & 4 deletions owner/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestSingle(t *testing.T) {
client := cluster.RandClient()
ctx := context.Background()
ic := infoschema.NewCache(2)
ic.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0, 0)
ic.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0)
d := NewDDL(
ctx,
WithEtcdClient(client),
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestCluster(t *testing.T) {

cli := cluster.Client(0)
ic := infoschema.NewCache(2)
ic.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0, 0)
ic.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0)
d := NewDDL(
context.Background(),
WithEtcdClient(cli),
Expand All @@ -131,7 +131,7 @@ func TestCluster(t *testing.T) {

cli1 := cluster.Client(1)
ic2 := infoschema.NewCache(2)
ic2.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0, 0)
ic2.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0)
d1 := NewDDL(
context.Background(),
WithEtcdClient(cli1),
Expand All @@ -156,7 +156,7 @@ func TestCluster(t *testing.T) {
// d3 (not owner) stop
cli3 := cluster.Client(3)
ic3 := infoschema.NewCache(2)
ic3.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0, 0)
ic3.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0)
d3 := NewDDL(
context.Background(),
WithEtcdClient(cli3),
Expand Down

0 comments on commit dab3f0b

Please sign in to comment.