Skip to content

Commit

Permalink
sessionctx/variable: fix incorrect parallel tests (#27981)
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun authored Sep 13, 2021
1 parent 9d3b67f commit c26038b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
3 changes: 2 additions & 1 deletion sessionctx/variable/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestSetSystemVariable(t *testing.T) {
v := variable.NewSessionVars()
v.GlobalVarsAccessor = variable.NewMockGlobalAccessor()
v.TimeZone = time.UTC

testCases := []struct {
key string
value string
Expand All @@ -53,9 +54,9 @@ func TestSetSystemVariable(t *testing.T) {
{variable.TiDBMemQuotaApplyCache, "1024", false},
{variable.TiDBEnableStmtSummary, "1", false},
}

for _, tc := range testCases {
t.Run(tc.key, func(t *testing.T) {
t.Parallel()
err := variable.SetSessionSystemVar(v, tc.key, tc.value)
if tc.err {
require.Error(t, err)
Expand Down
21 changes: 6 additions & 15 deletions sessionctx/variable/statusvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ import (
"github.com/stretchr/testify/require"
)

type mockStatusVarSuite struct {
ms *mockStatistics
}

func createStatusVarSuite(t *testing.T) (s *mockStatusVarSuite) {
s = new(mockStatusVarSuite)
s.ms = &mockStatistics{}
RegisterStatistics(s.ms)
return
}

// mockStatistics represents mocked statistics.
type mockStatistics struct{}

Expand All @@ -53,18 +42,20 @@ func (ms *mockStatistics) GetScope(status string) ScopeFlag {
return scope
}

func (ms *mockStatistics) Stats(vars *SessionVars) (map[string]interface{}, error) {
func (ms *mockStatistics) Stats(_ *SessionVars) (map[string]interface{}, error) {
m := make(map[string]interface{}, len(specificStatusScopes))
m[testStatus] = testStatusVal

return m, nil
}

func TestStatusVar(t *testing.T) {
s := createStatusVarSuite(t)
scope := s.ms.GetScope(testStatus)
ms := &mockStatistics{}
RegisterStatistics(ms)

scope := ms.GetScope(testStatus)
require.Equal(t, DefaultStatusVarScopeFlag, scope)
scope = s.ms.GetScope(testSessionStatus)
scope = ms.GetScope(testSessionStatus)
require.Equal(t, ScopeSession, scope)

vars, err := GetStatusVars(nil)
Expand Down

0 comments on commit c26038b

Please sign in to comment.