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

owner: migrate test-infra to testify #26770

Merged
merged 25 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f473cf7
migrate test-infra to testify for owner pkg
hu00yan Jul 31, 2021
8fc4271
migrate test-infra to testify for owner pkg
hu00yan Jul 31, 2021
ab21ef7
migrate test-infra to testify for owner pkg
hu00yan Jul 31, 2021
3761e4f
Merge branch 'master' into issue-26743
tisonkun Aug 2, 2021
7498bab
fix unused and wrong Errorf
hu00yan Aug 3, 2021
f8b9c65
Merge branch 'master' into issue-26743
zimulala Aug 4, 2021
ed6c225
Merge branch 'master' into issue-26743
ti-chi-bot Aug 4, 2021
3c7664a
Merge branch 'master' into issue-26743
ti-chi-bot Aug 4, 2021
c715e09
Merge branch 'master' into issue-26743
ti-chi-bot Aug 4, 2021
5fd5a88
Merge branch 'master' into issue-26743
ti-chi-bot Aug 4, 2021
c5de459
Merge branch 'master' into issue-26743
ti-chi-bot Aug 4, 2021
9bfbae4
Merge branch 'master' into issue-26743
ti-chi-bot Aug 4, 2021
c81d29f
Merge branch 'master' into issue-26743
ti-chi-bot Aug 4, 2021
ffaff0b
Merge branch 'master' into issue-26743
ti-chi-bot Aug 4, 2021
10938cb
Merge branch 'master' into issue-26743
ti-chi-bot Aug 4, 2021
eea7495
remove TestCluster t.Parallel()
hu00yan Aug 4, 2021
5e63574
Merge branch 'master' into issue-26743
zhouqiang-cl Aug 5, 2021
9b698a4
fix fail tests
tisonkun Aug 5, 2021
1ea7c19
replace conditional compile with skip
tisonkun Aug 5, 2021
94f5c7b
Merge branch 'master' into issue-26743
tisonkun Aug 6, 2021
f06e9f3
Merge branch 'master' into issue-26743
ti-chi-bot Aug 9, 2021
7740560
Merge branch 'master' into issue-26743
ti-chi-bot Aug 9, 2021
f95f6a5
Merge branch 'master' into issue-26743
ti-chi-bot Aug 9, 2021
d3cb5e8
Merge branch 'master' into issue-26743
ti-chi-bot Aug 9, 2021
fd0828c
Merge branch 'master' into issue-26743
ti-chi-bot Aug 9, 2021
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
75 changes: 26 additions & 49 deletions owner/fail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// 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 !windows

package owner
Expand All @@ -24,110 +25,86 @@ import (
"testing"
"time"

. "github.com/pingcap/check"
"github.com/pingcap/failpoint"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/testleak"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.etcd.io/etcd/clientv3"
"google.golang.org/grpc"
)

// Ignore this test on the windows platform, because calling unix socket with address in
// host:port format fails on windows.
func TestT(t *testing.T) {
CustomVerboseFlag = true
logLevel := os.Getenv("log_level")
err := logutil.InitLogger(logutil.NewLogConfig(logLevel, "", "", logutil.EmptyFileLogConfig, false))
if err != nil {
t.Fatal(err)
}
TestingT(t)
}

var _ = Suite(&testSuite{})

type testSuite struct {
}

func (s *testSuite) SetUpSuite(c *C) {
}

func (s *testSuite) TearDownSuite(c *C) {
}

var (
dialTimeout = 5 * time.Second
dialTimeout = 3 * time.Second
retryCnt = math.MaxInt32
)

func (s *testSuite) TestFailNewSession(c *C) {
os.Remove("new_session:0")
func TestFailNewSession(t *testing.T) {
_ = os.Remove("new_session:0")
ln, err := net.Listen("unix", "new_session:0")
c.Assert(err, IsNil)
require.NoError(t, err)

addr := ln.Addr()
endpoints := []string{fmt.Sprintf("%s://%s", addr.Network(), addr.String())}
c.Assert(err, IsNil)
require.NoError(t, err)

srv := grpc.NewServer(grpc.ConnectionTimeout(time.Minute))
var stop sync.WaitGroup
stop.Add(1)

go func() {
if err = srv.Serve(ln); err != nil {
c.Errorf("can't serve gRPC requests %v", err)
}
stop.Done()
defer stop.Done()
err = srv.Serve(ln)
assert.NoError(t, err)
}()

leakFunc := testleak.AfterTest(c)
defer func() {
srv.Stop()
stop.Wait()
leakFunc()
}()

func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: endpoints,
DialTimeout: dialTimeout,
})
c.Assert(err, IsNil)
require.NoError(t, err)
defer func() {
if cli != nil {
cli.Close()
_ = cli.Close()
}
c.Assert(failpoint.Disable("github.com/pingcap/tidb/owner/closeClient"), IsNil)
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/owner/closeClient"))
}()
c.Assert(failpoint.Enable("github.com/pingcap/tidb/owner/closeClient", `return(true)`), IsNil)
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/owner/closeClient", `return(true)`))

// TODO: It takes more than 2s here in etcd client, the CI takes 5s to run this test.
// The config is hard coded, not way to control it outside.
// Call stack:
// https://github.com/etcd-io/etcd/blob/ae9734e/clientv3/concurrency/session.go#L38
// https://github.com/etcd-io/etcd/blob/ae9734ed278b7a1a7dfc82e800471ebbf9fce56f/clientv3/client.go#L253
// https://github.com/etcd-io/etcd/blob/ae9734ed278b7a1a7dfc82e800471ebbf9fce56f/clientv3/retry_interceptor.go#L63
_, err = NewSession(context.Background(), "fail_new_serssion", cli, retryCnt, ManagerSessionTTL)
_, err = NewSession(context.Background(), "fail_new_session", cli, retryCnt, ManagerSessionTTL)
isContextDone := terror.ErrorEqual(grpc.ErrClientConnClosing, err) || terror.ErrorEqual(context.Canceled, err)
c.Assert(isContextDone, IsTrue, Commentf("err %v", err))
require.Truef(t, isContextDone, "err %v", err)
}()

func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: endpoints,
DialTimeout: dialTimeout,
})
c.Assert(err, IsNil)
require.NoError(t, err)
defer func() {
if cli != nil {
cli.Close()
_ = cli.Close()
}
c.Assert(failpoint.Disable("github.com/pingcap/tidb/owner/closeGrpc"), IsNil)
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/owner/closeGrpc"))
}()
c.Assert(failpoint.Enable("github.com/pingcap/tidb/owner/closeGrpc", `return(true)`), IsNil)
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/owner/closeGrpc", `return(true)`))

// TODO: It takes more than 2s here in etcd client, the CI takes 5s to run this test.
// The config is hard coded, not way to control it outside.
_, err = NewSession(context.Background(), "fail_new_serssion", cli, retryCnt, ManagerSessionTTL)
_, err = NewSession(context.Background(), "fail_new_session", cli, retryCnt, ManagerSessionTTL)
isContextDone := terror.ErrorEqual(grpc.ErrClientConnClosing, err) || terror.ErrorEqual(context.Canceled, err)
c.Assert(isContextDone, IsTrue, Commentf("err %v", err))
require.Truef(t, isContextDone, "err %v", err)
}()
}
29 changes: 29 additions & 0 deletions owner/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//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 owner

import (
"testing"

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

func TestMain(m *testing.M) {
testbridge.WorkaroundGoCheckFlags()
opts := []goleak.Option{
goleak.IgnoreTopFunction("go.etcd.io/etcd/pkg/logutil.(*MergeLogger).outputLoop"),
}
goleak.VerifyTestMain(m, opts...)
}
Loading