Skip to content

Commit

Permalink
statistics: migrate test-infra to testify for statistics/handle/updat…
Browse files Browse the repository at this point in the history
…e_list_test.go (pingcap#28208)
  • Loading branch information
feitian124 authored Sep 21, 2021
1 parent cd0b4e1 commit 9a62f05
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
31 changes: 31 additions & 0 deletions statistics/handle/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package handle

import (
"testing"

"github.com/pingcap/tidb/util/testbridge"
"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
opts := []goleak.Option{
goleak.IgnoreTopFunction("go.etcd.io/etcd/pkg/logutil.(*MergeLogger).outputLoop"),
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
}
testbridge.WorkaroundGoCheckFlags()
goleak.VerifyTestMain(m, opts...)
}
20 changes: 9 additions & 11 deletions statistics/handle/update_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@
package handle

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

"github.com/pingcap/tidb/statistics"
"github.com/stretchr/testify/require"
)

var _ = Suite(&testUpdateListSuite{})

type testUpdateListSuite struct {
}

func (s *testUpdateListSuite) TestInsertAndDelete(c *C) {
func TestInsertAndDelete(t *testing.T) {
t.Parallel()
h := Handle{
listHead: &SessionStatsCollector{mapper: make(tableDeltaMap)},
feedback: statistics.NewQueryFeedbackMap(),
Expand All @@ -38,13 +36,13 @@ func (s *testUpdateListSuite) TestInsertAndDelete(c *C) {
items[4].Delete() // delete head
h.sweepList()

c.Assert(h.listHead.next, Equals, items[3])
c.Assert(items[3].next, Equals, items[1])
c.Assert(items[1].next, IsNil)
require.Equal(t, items[3], h.listHead.next)
require.Equal(t, items[1], items[3].next)
require.Nil(t, items[1].next)

// delete rest
items[1].Delete()
items[3].Delete()
h.sweepList()
c.Assert(h.listHead.next, IsNil)
require.Nil(t, h.listHead.next)
}

0 comments on commit 9a62f05

Please sign in to comment.