Skip to content

Commit

Permalink
test: add test cases
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <[email protected]>
  • Loading branch information
Rustin170506 committed May 22, 2024
1 parent 97f8088 commit 4db4e82
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions pkg/sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1605,3 +1605,69 @@ func TestTiDBLowResTSOUpdateInterval(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "1000", val)
}

func TestSetEnableColumnTrackingAndPersistAnalyzeOptions(t *testing.T) {
vars := NewSessionVars(nil)
mock := NewMockGlobalAccessor4Tests()
mock.SessionVars = vars
vars.GlobalVarsAccessor = mock

// Test EnableColumnTracking
val, err := mock.GetGlobalSysVar(TiDBEnableColumnTracking)
require.NoError(t, err)
require.Equal(t, Off, val)
err = mock.SetGlobalSysVar(context.Background(), TiDBEnableColumnTracking, On)
require.NoError(t, err)
val, err = mock.GetGlobalSysVar(TiDBEnableColumnTracking)
require.NoError(t, err)
require.Equal(t, On, val)
// Rest back.
err = mock.SetGlobalSysVar(context.Background(), TiDBEnableColumnTracking, Off)
require.NoError(t, err)

// Test PersistAnalyzeOptions
val, err = mock.GetGlobalSysVar(TiDBPersistAnalyzeOptions)
require.NoError(t, err)
require.Equal(t, On, val)
err = mock.SetGlobalSysVar(context.Background(), TiDBPersistAnalyzeOptions, Off)
require.NoError(t, err)
val, err = mock.GetGlobalSysVar(TiDBPersistAnalyzeOptions)
require.NoError(t, err)
require.Equal(t, Off, val)
// Rest back
err = mock.SetGlobalSysVar(context.Background(), TiDBPersistAnalyzeOptions, On)
require.NoError(t, err)

// Set EnableColumnTracking to true when PersistAnalyzeOptions is false
// Set to false first.
err = mock.SetGlobalSysVar(context.Background(), TiDBEnableColumnTracking, Off)
require.NoError(t, err)
err = mock.SetGlobalSysVar(context.Background(), TiDBPersistAnalyzeOptions, Off)
require.NoError(t, err)
val, err = mock.GetGlobalSysVar(TiDBPersistAnalyzeOptions)
require.NoError(t, err)
require.Equal(t, Off, val)
err = mock.SetGlobalSysVar(context.Background(), TiDBEnableColumnTracking, On)
require.Error(t, err, "enable column tracking requires to persist analyze options")
val, err = mock.GetGlobalSysVar(TiDBEnableColumnTracking)
require.NoError(t, err)
require.Equal(t, Off, val)

// Set PersistAnalyzeOptions to false when EnableColumnTracking is true
// Set to true first.
err = mock.SetGlobalSysVar(context.Background(), TiDBPersistAnalyzeOptions, On)
require.NoError(t, err)
val, err = mock.GetGlobalSysVar(TiDBPersistAnalyzeOptions)
require.NoError(t, err)
require.Equal(t, On, val)
err = mock.SetGlobalSysVar(context.Background(), TiDBEnableColumnTracking, On)
require.NoError(t, err)
val, err = mock.GetGlobalSysVar(TiDBEnableColumnTracking)
require.NoError(t, err)
require.Equal(t, On, val)
err = mock.SetGlobalSysVar(context.Background(), TiDBPersistAnalyzeOptions, Off)
require.Error(t, err, "persist analyze options requires to enable column tracking")
val, err = mock.GetGlobalSysVar(TiDBPersistAnalyzeOptions)
require.NoError(t, err)
require.Equal(t, On, val)
}

0 comments on commit 4db4e82

Please sign in to comment.