diff --git a/sessionctx/variable/session_test.go b/sessionctx/variable/session_test.go index 6d461f772c..708b963958 100644 --- a/sessionctx/variable/session_test.go +++ b/sessionctx/variable/session_test.go @@ -15,6 +15,7 @@ package variable_test import ( + "sync" "testing" "time" @@ -34,6 +35,7 @@ func TestSetSystemVariable(t *testing.T) { v := variable.NewSessionVars() v.GlobalVarsAccessor = variable.NewMockGlobalAccessor() v.TimeZone = time.UTC + mtx := new(sync.Mutex) testCases := []struct { key string @@ -57,7 +59,10 @@ func TestSetSystemVariable(t *testing.T) { for _, tc := range testCases { t.Run(tc.key, func(t *testing.T) { + t.Parallel() + mtx.Lock() err := variable.SetSessionSystemVar(v, tc.key, tc.value) + mtx.Unlock() if tc.err { require.Error(t, err) } else { diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 4a972b830a..75f4cc1695 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -1269,7 +1269,7 @@ var defaultSysVars = []*SysVar{ s.EnableFastAnalyze = TiDBOptOn(val) return nil }}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBSkipIsolationLevelCheck, skipInit: true, Value: BoolToOnOff(DefTiDBSkipIsolationLevelCheck), Type: TypeBool}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBSkipIsolationLevelCheck, Value: BoolToOnOff(DefTiDBSkipIsolationLevelCheck), Type: TypeBool}, {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableRateLimitAction, Value: BoolToOnOff(DefTiDBEnableRateLimitAction), Type: TypeBool, SetSession: func(s *SessionVars, val string) error { s.EnabledRateLimitAction = TiDBOptOn(val) return nil diff --git a/sessionctx/variable/sysvar_test.go b/sessionctx/variable/sysvar_test.go index 78793a1725..257e3beec8 100644 --- a/sessionctx/variable/sysvar_test.go +++ b/sessionctx/variable/sysvar_test.go @@ -419,8 +419,21 @@ func TestTxnIsolation(t *testing.T) { _, err = sv.Validate(vars, "read-uncommitted", ScopeSession) require.Equal(t, "[variable:8048]The isolation level 'READ-UNCOMMITTED' is not supported. Set tidb_skip_isolation_level_check=1 to skip this error", err.Error()) - vars.systems[TiDBSkipIsolationLevelCheck] = "ON" + // Enable global skip isolation check doesn't affect current session + require.Nil(t, GetSysVar(TiDBSkipIsolationLevelCheck).SetGlobalFromHook(vars, "ON", true)) + _, err = sv.Validate(vars, "Serializable", ScopeSession) + require.Equal(t, "[variable:8048]The isolation level 'SERIALIZABLE' is not supported. Set tidb_skip_isolation_level_check=1 to skip this error", err.Error()) + // Enable session skip isolation check + require.Nil(t, GetSysVar(TiDBSkipIsolationLevelCheck).SetSessionFromHook(vars, "ON")) + + val, err = sv.Validate(vars, "Serializable", ScopeSession) + require.NoError(t, err) + require.Equal(t, "SERIALIZABLE", val) + + // Init TiDBSkipIsolationLevelCheck like what loadCommonGlobalVariables does + vars = NewSessionVars() + require.NoError(t, vars.SetSystemVarWithRelaxedValidation(TiDBSkipIsolationLevelCheck, "1")) val, err = sv.Validate(vars, "Serializable", ScopeSession) require.NoError(t, err) require.Equal(t, "SERIALIZABLE", val)