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

errno: migrate test-infra to testify #26082

Merged
merged 8 commits into from
Jul 10, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
55 changes: 24 additions & 31 deletions errno/infoschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@ package errno
import (
"testing"

. "github.com/pingcap/check"
"github.com/stretchr/testify/assert"
)

func TestT(t *testing.T) {
TestingT(t)
}

var _ = Suite(&testErrno{})

type testErrno struct{}

func (s *testErrno) TestCopySafety(c *C) {
func TestCopySafety(t *testing.T) {
t.Parallel()

IncrementError(123, "user", "host")
IncrementError(321, "user2", "host2")
Expand All @@ -48,42 +41,42 @@ func (s *testErrno) TestCopySafety(c *C) {
IncrementWarning(333, "c", "d")

// global stats
c.Assert(stats.global[123].ErrorCount, Equals, 3)
c.Assert(globalCopy[123].ErrorCount, Equals, 1)
assert.Equal(t, 3, stats.global[123].ErrorCount)
assert.Equal(t, 1, globalCopy[123].ErrorCount)

// user stats
c.Assert(len(stats.users), Equals, 6)
c.Assert(len(userCopy), Equals, 3)
c.Assert(stats.users["user"][123].ErrorCount, Equals, 2)
c.Assert(stats.users["user"][123].WarningCount, Equals, 2)
c.Assert(userCopy["user"][123].ErrorCount, Equals, 1)
c.Assert(userCopy["user"][123].WarningCount, Equals, 1)
assert.Len(t, stats.users, 6)
assert.Len(t, userCopy, 3)
assert.Equal(t, 2, stats.users["user"][123].ErrorCount)
assert.Equal(t, 2, stats.users["user"][123].WarningCount)
assert.Equal(t, 1, userCopy["user"][123].ErrorCount)
assert.Equal(t, 1, userCopy["user"][123].WarningCount)

// ensure there is no user3 in userCopy
_, ok := userCopy["user3"]
c.Assert(ok, IsFalse)
assert.False(t, ok)
_, ok = stats.users["user3"]
c.Assert(ok, IsTrue)
assert.True(t, ok)
_, ok = userCopy["a"]
c.Assert(ok, IsFalse)
assert.False(t, ok)
_, ok = stats.users["a"]
c.Assert(ok, IsTrue)
assert.True(t, ok)

// host stats
c.Assert(len(stats.hosts), Equals, 5)
c.Assert(len(hostCopy), Equals, 3)
assert.Len(t, stats.hosts, 5)
assert.Len(t, hostCopy, 3)

IncrementError(123, "user3", "newhost")
c.Assert(len(stats.hosts), Equals, 6)
c.Assert(len(hostCopy), Equals, 3)
assert.Len(t, stats.hosts, 6)
assert.Len(t, hostCopy, 3)

// ensure there is no newhost in hostCopy
_, ok = hostCopy["newhost"]
c.Assert(ok, IsFalse)
assert.False(t, ok)
_, ok = stats.hosts["newhost"]
c.Assert(ok, IsTrue)
assert.True(t, ok)
_, ok = hostCopy["b"]
c.Assert(ok, IsFalse)
assert.False(t, ok)
_, ok = stats.hosts["b"]
c.Assert(ok, IsTrue)

assert.True(t, ok)
}
26 changes: 26 additions & 0 deletions errno/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 errno

import (
"os"
"testing"

"github.com/pingcap/tidb/util/testbridge"
)

func TestMain(m *testing.M) {
testbridge.WorkaroundGoCheckFlags()
os.Exit(m.Run())
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ require (
github.com/rivo/uniseg v0.2.0 // indirect
github.com/shirou/gopsutil v3.21.2+incompatible
github.com/soheilhy/cmux v0.1.4
github.com/stretchr/testify v1.7.0
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
github.com/tikv/client-go/v2 v2.0.0-alpha.0.20210709052506-aadf3cf62721
github.com/tikv/pd v1.1.0-beta.0.20210323121136-78679e5e209d
Expand Down
34 changes: 34 additions & 0 deletions util/testbridge/bridge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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.

// +build !codes

package testbridge

import (
"flag"
)

// WorkaroundGoCheckFlags registers flags of go-check for pkg does not import go-check
// to workaround the go-check flags passed in Makefile.
//
// TODO: Remove this function when the migration from go-check to testify[1] is done.
// [1] https://github.com/pingcap/tidb/issues/26022
func WorkaroundGoCheckFlags() {
if flag.Lookup("check.timeout") == nil {
_ = flag.Duration("check.timeout", 0, "WorkaroundGoCheckFlags: check.timeout")
}
if flag.Lookup("check.p") == nil {
_ = flag.Bool("check.p", false, "WorkaroundGoCheckFlags: check.p")
}
}