-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util/stmtsummary: migrate test-infra to testify (part 0) #26869
Changes from 3 commits
a31346d
65fb97a
fc74f19
24892e3
2be4a6f
4434dae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2021 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package stmtsummary | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingcap/tidb/util/testbridge" | ||
"go.uber.org/goleak" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
testbridge.WorkaroundGoCheckFlags() | ||
goleak.VerifyTestMain(m) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,108 +14,108 @@ | |
package stmtsummary | ||
|
||
import ( | ||
. "github.com/pingcap/check" | ||
"testing" | ||
|
||
"github.com/pingcap/tidb/config" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var _ = Suite(&testVariablesSuite{}) | ||
|
||
type testVariablesSuite struct { | ||
} | ||
|
||
func (s *testVariablesSuite) TestSetInVariable(c *C) { | ||
func TestSetInVariable(t *testing.T) { | ||
t.Parallel() | ||
sv := newSysVars() | ||
st := sv.getVariable(typeMaxStmtCount) | ||
c.Assert(st, Equals, int64(config.GetGlobalConfig().StmtSummary.MaxStmtCount)) | ||
require.Equal(t, int64(config.GetGlobalConfig().StmtSummary.MaxStmtCount), st) | ||
|
||
err := sv.setVariable(typeMaxStmtCount, "10", false) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
st = sv.getVariable(typeMaxStmtCount) | ||
c.Assert(st, Equals, int64(10)) | ||
require.Equal(t, int64(10), st) | ||
err = sv.setVariable(typeMaxStmtCount, "100", false) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
st = sv.getVariable(typeMaxStmtCount) | ||
c.Assert(st, Equals, int64(100)) | ||
require.Equal(t, int64(100), st) | ||
err = sv.setVariable(typeMaxStmtCount, "10", true) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
st = sv.getVariable(typeMaxStmtCount) | ||
c.Assert(st, Equals, int64(10)) | ||
require.Equal(t, int64(10), st) | ||
err = sv.setVariable(typeMaxStmtCount, "100", true) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
st = sv.getVariable(typeMaxStmtCount) | ||
c.Assert(st, Equals, int64(100)) | ||
require.Equal(t, int64(100), st) | ||
err = sv.setVariable(typeMaxStmtCount, "10", false) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
st = sv.getVariable(typeMaxStmtCount) | ||
c.Assert(st, Equals, int64(100)) | ||
require.Equal(t, int64(100), st) | ||
err = sv.setVariable(typeMaxStmtCount, "", true) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
st = sv.getVariable(typeMaxStmtCount) | ||
c.Assert(st, Equals, int64(10)) | ||
require.Equal(t, int64(10), st) | ||
err = sv.setVariable(typeMaxStmtCount, "", false) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
st = sv.getVariable(typeMaxStmtCount) | ||
c.Assert(st, Equals, int64(config.GetGlobalConfig().StmtSummary.MaxStmtCount)) | ||
require.Equal(t, int64(config.GetGlobalConfig().StmtSummary.MaxStmtCount), st) | ||
} | ||
|
||
func (s *testVariablesSuite) TestSetBoolVariable(c *C) { | ||
func TestSetBoolVariable(t *testing.T) { | ||
t.Parallel() | ||
sv := newSysVars() | ||
en := sv.getVariable(typeEnable) | ||
c.Assert(en > 0, Equals, config.GetGlobalConfig().StmtSummary.Enable) | ||
require.Equal(t, config.GetGlobalConfig().StmtSummary.Enable, en > 0) | ||
|
||
err := sv.setVariable(typeEnable, "OFF", false) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
en = sv.getVariable(typeEnable) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
c.Assert(en > 0, Equals, false) | ||
require.LessOrEqual(t, en, 0 ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. format it. |
||
err = sv.setVariable(typeEnable, "ON", false) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
en = sv.getVariable(typeEnable) | ||
c.Assert(en > 0, Equals, true) | ||
require.Greater(t, en, 0) | ||
err = sv.setVariable(typeEnable, "OFF", true) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
en = sv.getVariable(typeEnable) | ||
c.Assert(en > 0, Equals, false) | ||
require.LessOrEqual(t, en, 0 ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
err = sv.setVariable(typeEnable, "ON", true) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
en = sv.getVariable(typeEnable) | ||
c.Assert(en > 0, Equals, true) | ||
require.Greater(t, en, 0) | ||
err = sv.setVariable(typeEnable, "OFF", false) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
en = sv.getVariable(typeEnable) | ||
c.Assert(en > 0, Equals, true) | ||
require.Greater(t, en, 0) | ||
err = sv.setVariable(typeEnable, "", true) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
en = sv.getVariable(typeEnable) | ||
c.Assert(en > 0, Equals, false) | ||
require.LessOrEqual(t, en, 0 ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
err = sv.setVariable(typeEnable, "ON", false) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
en = sv.getVariable(typeEnable) | ||
c.Assert(en > 0, Equals, true) | ||
require.Greater(t, en, 0) | ||
err = sv.setVariable(typeEnable, "", false) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
en = sv.getVariable(typeEnable) | ||
c.Assert(en > 0, Equals, config.GetGlobalConfig().StmtSummary.Enable) | ||
require.Equal(t, config.GetGlobalConfig().StmtSummary.Enable, en > 0) | ||
} | ||
|
||
func (s *testVariablesSuite) TestMinValue(c *C) { | ||
func TestMinValue(t *testing.T) { | ||
t.Parallel() | ||
sv := newSysVars() | ||
err := sv.setVariable(typeMaxStmtCount, "0", false) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
v := sv.getVariable(typeMaxStmtCount) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
c.Assert(v, Greater, int64(0)) | ||
require.Greater(t, v, int64(0)) | ||
|
||
err = sv.setVariable(typeMaxSQLLength, "0", false) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
v = sv.getVariable(typeMaxSQLLength) | ||
c.Assert(v, Equals, int64(0)) | ||
require.Equal(t, int64(0), v) | ||
|
||
err = sv.setVariable(typeHistorySize, "0", false) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
v = sv.getVariable(typeHistorySize) | ||
c.Assert(v, Equals, int64(0)) | ||
require.Equal(t, int64(0), v) | ||
|
||
err = sv.setVariable(typeRefreshInterval, "0", false) | ||
c.Assert(err, IsNil) | ||
require.NoError(t, err) | ||
v = sv.getVariable(typeRefreshInterval) | ||
c.Assert(v, Greater, int64(0)) | ||
require.Greater(t, v, int64(0)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that we don't need the var
st
. How about the following code?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for your suggestion.
please forgive me,but i think keep the var
st
there is more clear and more consistent with the err partanother reason is that this is a migrate, less change may let the whole job faster done and less mistake injected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.