Skip to content
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

Merged
merged 6 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions util/stmtsummary/main_test.go
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)
}
98 changes: 49 additions & 49 deletions util/stmtsummary/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

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?

require.Equal(t, int64(10), sv.getVariable(typeMaxStmtCount))

Copy link
Contributor Author

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 part

	err = sv.setVariable(typeEnable, "OFF", false)
	require.NoError(t, err)

another reason is that this is a migrate, less change may let the whole job faster done and less mistake injected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

c.Assert(en > 0, Equals, false)
require.LessOrEqual(t, en, 0 )
Copy link
Member

Choose a reason for hiding this comment

The 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 )
Copy link
Member

Choose a reason for hiding this comment

The 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 )
Copy link
Member

Choose a reason for hiding this comment

The 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)
Copy link
Member

Choose a reason for hiding this comment

The 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))
}