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

executor: migrate test infra to testify for concurrent_map_test.go and collation_test.go #29553

Merged
merged 11 commits into from
Nov 11, 2021
45 changes: 21 additions & 24 deletions executor/collation_test.go → executor/collation_serial_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 PingCAP, Inc.
// 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.
Expand All @@ -15,21 +15,18 @@
package executor

import (
. "github.com/pingcap/check"
"testing"

"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/mock"
"github.com/stretchr/testify/require"
)

var _ = SerialSuites(&testCollationSuite{})

type testCollationSuite struct {
}

func (s *testCollationSuite) TestVecGroupChecker(c *C) {
func TestVecGroupChecker(t *testing.T) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)

Expand All @@ -53,35 +50,35 @@ func (s *testCollationSuite) TestVecGroupChecker(c *C) {
tp.Collate = "bin"
groupChecker.reset()
_, err := groupChecker.splitIntoGroups(chk)
c.Assert(err, IsNil)
require.NoError(t, err)
for i := 0; i < 6; i++ {
b, e := groupChecker.getNextGroup()
c.Assert(b, Equals, i)
c.Assert(e, Equals, i+1)
require.Equal(t, b, i)
require.Equal(t, e, i+1)
}
c.Assert(groupChecker.isExhausted(), IsTrue)
require.True(t, groupChecker.isExhausted())

tp.Collate = "utf8_general_ci"
groupChecker.reset()
_, err = groupChecker.splitIntoGroups(chk)
c.Assert(err, IsNil)
require.NoError(t, err)
for i := 0; i < 3; i++ {
b, e := groupChecker.getNextGroup()
c.Assert(b, Equals, i*2)
c.Assert(e, Equals, i*2+2)
require.Equal(t, b, i*2)
require.Equal(t, e, i*2+2)
}
c.Assert(groupChecker.isExhausted(), IsTrue)
require.True(t, groupChecker.isExhausted())

tp.Collate = "utf8_unicode_ci"
groupChecker.reset()
_, err = groupChecker.splitIntoGroups(chk)
c.Assert(err, IsNil)
require.NoError(t, err)
for i := 0; i < 3; i++ {
b, e := groupChecker.getNextGroup()
c.Assert(b, Equals, i*2)
c.Assert(e, Equals, i*2+2)
require.Equal(t, b, i*2)
require.Equal(t, e, i*2+2)
}
c.Assert(groupChecker.isExhausted(), IsTrue)
require.True(t, groupChecker.isExhausted())

// test padding
tp.Collate = "utf8_bin"
Expand All @@ -92,9 +89,9 @@ func (s *testCollationSuite) TestVecGroupChecker(c *C) {
chk.Column(0).AppendString("a ")
groupChecker.reset()
_, err = groupChecker.splitIntoGroups(chk)
c.Assert(err, IsNil)
require.NoError(t, err)
b, e := groupChecker.getNextGroup()
c.Assert(b, Equals, 0)
c.Assert(e, Equals, 3)
c.Assert(groupChecker.isExhausted(), IsTrue)
require.Equal(t, b, 0)
require.Equal(t, e, 3)
require.True(t, groupChecker.isExhausted())
}
18 changes: 10 additions & 8 deletions executor/concurrent_map_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 PingCAP, Inc.
// 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.
Expand All @@ -16,19 +16,21 @@ package executor

import (
"sync"
"testing"

. "github.com/pingcap/check"
"github.com/pingcap/tidb/util/chunk"
"github.com/stretchr/testify/require"
)

// TestConcurrentMap first inserts 1000 entries, then checks them
func (cm *pkgTestSuite) TestConcurrentMap(c *C) {
func TestConcurrentMap(t *testing.T) {
t.Parallel()
m := newConcurrentMap()
const iterations = 1000
const mod = 111
wg := &sync.WaitGroup{}
wg.Add(2)
// Using go routines insert 1000 entires into the map.
// Using go routines insert 1000 entries into the map.
go func() {
defer wg.Done()
for i := 0; i < iterations/2; i++ {
Expand All @@ -50,17 +52,17 @@ func (cm *pkgTestSuite) TestConcurrentMap(c *C) {
for i := 0; i < iterations; i++ {
found := false
for en, ok := m.Get(uint64(i % mod)); en != nil; en = en.next {
c.Assert(ok, IsTrue)
require.True(t, ok)
if en.ptr.RowIdx == uint32(i) && en.ptr.ChkIdx == uint32(i) {
found = true
}
}
c.Assert(found, IsTrue)
require.True(t, found)
}
// test some unexpected cases
_, ok := m.Get(uint64(mod))
c.Assert(ok, IsFalse)
require.False(t, ok)

_, ok = m.Get(uint64(mod + 1))
c.Assert(ok, IsFalse)
require.False(t, ok)
}