From 77cf828e3bfbe6017859c7523f8951726d145c1d Mon Sep 17 00:00:00 2001 From: Youra Cho Date: Mon, 22 Nov 2021 18:24:12 -0800 Subject: [PATCH 1/3] Set` lc_time_names` variable to ReadOnly true --- sessionctx/variable/noop.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sessionctx/variable/noop.go b/sessionctx/variable/noop.go index ceff418f39740..e045f707ef029 100644 --- a/sessionctx/variable/noop.go +++ b/sessionctx/variable/noop.go @@ -483,7 +483,7 @@ var noopSysVars = []*SysVar{ {Scope: ScopeNone, Name: "tmpdir", Value: "/var/tmp/"}, {Scope: ScopeGlobal, Name: "innodb_thread_concurrency", Value: "0"}, {Scope: ScopeGlobal, Name: "innodb_buffer_pool_dump_pct", Value: ""}, - {Scope: ScopeGlobal | ScopeSession, Name: "lc_time_names", Value: "en_US"}, + {Scope: ScopeGlobal | ScopeSession, Name: "lc_time_names", Value: "en_US", ReadOnly: true}, {Scope: ScopeGlobal | ScopeSession, Name: "max_statement_time", Value: ""}, {Scope: ScopeGlobal | ScopeSession, Name: EndMarkersInJSON, Value: Off, Type: TypeBool, IsHintUpdatable: true}, {Scope: ScopeGlobal, Name: AvoidTemporalUpgrade, Value: Off, Type: TypeBool}, From 00257e649e581f9cc7963ecf9ddfe95ddde76ebb Mon Sep 17 00:00:00 2001 From: Youra Cho Date: Mon, 22 Nov 2021 22:07:06 -0800 Subject: [PATCH 2/3] Add new test case and fix gofmt errors --- sessionctx/variable/sysvar_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sessionctx/variable/sysvar_test.go b/sessionctx/variable/sysvar_test.go index b0c4e94e84490..0c1fbc13577dd 100644 --- a/sessionctx/variable/sysvar_test.go +++ b/sessionctx/variable/sysvar_test.go @@ -525,7 +525,7 @@ func TestSkipInit(t *testing.T) { require.True(t, sv.SkipInit()) } -// IsNoop is used by the documentation to auto-generate docs for real sysvars. +// TestIsNoop is used by the documentation to auto-generate docs for real sysvars. func TestIsNoop(t *testing.T) { sv := GetSysVar(TiDBMultiStatementMode) require.False(t, sv.IsNoop) @@ -639,7 +639,7 @@ func TestInstanceScopedVars(t *testing.T) { require.Equal(t, vars.TxnScope.GetVarValue(), val) } -// Test that sysvars defaults are logically valid. i.e. +// TestDefaultValuesAreSettable that sysvars defaults are logically valid. i.e. // the default itself must validate without error provided the scope and read-only is correct. // The default values should also be normalized for consistency. func TestDefaultValuesAreSettable(t *testing.T) { @@ -660,7 +660,7 @@ func TestDefaultValuesAreSettable(t *testing.T) { } } -// This tests that sysvars are logically correct with getter and setter functions. +// TestSettersandGetters tests that sysvars are logically correct with getter and setter functions. // i.e. it doesn't make sense to have a SetSession function on a variable that is only globally scoped. func TestSettersandGetters(t *testing.T) { for _, sv := range GetSysVars() { @@ -759,6 +759,14 @@ func TestIdentity(t *testing.T) { require.Equal(t, val, "21") } +func TestLcTimeNamesReadOnly(t *testing.T) { + sv := GetSysVar("lc_time_names") + vars := NewSessionVars() + vars.GlobalVarsAccessor = NewMockGlobalAccessor4Tests() + _, err := sv.Validate(vars, "newvalue", ScopeGlobal) + require.True(t, terror.ErrorEqual(err, ErrReadOnly)) +} + func TestDDLWorkers(t *testing.T) { svWorkerCount, svBatchSize := GetSysVar(TiDBDDLReorgWorkerCount), GetSysVar(TiDBDDLReorgBatchSize) vars := NewSessionVars() From 2038d793996b229a73f235318daa0e47ece33feb Mon Sep 17 00:00:00 2001 From: Youra Cho Date: Tue, 23 Nov 2021 12:08:41 -0800 Subject: [PATCH 3/3] Update TestLcTimeNamesReadOnly function --- sessionctx/variable/sysvar_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sessionctx/variable/sysvar_test.go b/sessionctx/variable/sysvar_test.go index 0c1fbc13577dd..a46049d8af029 100644 --- a/sessionctx/variable/sysvar_test.go +++ b/sessionctx/variable/sysvar_test.go @@ -764,7 +764,7 @@ func TestLcTimeNamesReadOnly(t *testing.T) { vars := NewSessionVars() vars.GlobalVarsAccessor = NewMockGlobalAccessor4Tests() _, err := sv.Validate(vars, "newvalue", ScopeGlobal) - require.True(t, terror.ErrorEqual(err, ErrReadOnly)) + require.Error(t, err) } func TestDDLWorkers(t *testing.T) {