-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9d6172
commit ac9775c
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// 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 capture | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/pingcap/tiflow/pkg/etcd" | ||
"github.com/stretchr/testify/require" | ||
"go.etcd.io/etcd/clientv3" | ||
"go.etcd.io/etcd/pkg/logutil" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/backoff" | ||
) | ||
|
||
func TestReset(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
|
||
// init etcd mocker | ||
clientURL, etcdServer, err := etcd.SetupEmbedEtcd(t.TempDir()) | ||
require.Nil(t, err) | ||
logConfig := logutil.DefaultZapLoggerConfig | ||
logConfig.Level = zap.NewAtomicLevelAt(zapcore.ErrorLevel) | ||
|
||
etcdCli, err := clientv3.New(clientv3.Config{ | ||
Endpoints: []string{clientURL.String()}, | ||
Context: ctx, | ||
LogConfig: &logConfig, | ||
DialTimeout: 3 * time.Second, | ||
DialOptions: []grpc.DialOption{ | ||
grpc.WithBlock(), | ||
grpc.WithConnectParams(grpc.ConnectParams{ | ||
Backoff: backoff.Config{ | ||
BaseDelay: time.Second, | ||
Multiplier: 1.1, | ||
Jitter: 0.1, | ||
MaxDelay: 3 * time.Second, | ||
}, | ||
MinConnectTimeout: 3 * time.Second, | ||
}), | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
client := etcd.NewCDCEtcdClient(context.TODO(), etcdCli) | ||
|
||
cp := NewCapture4Test(nil) | ||
cp.EtcdClient = &client | ||
|
||
// simulate network isolation scenarios | ||
etcdServer.Close() | ||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
go func() { | ||
err = cp.reset(ctx) | ||
require.Regexp(t, ".*context canceled.*", err) | ||
wg.Done() | ||
}() | ||
time.Sleep(100 * time.Millisecond) | ||
info := cp.Info() | ||
require.NotNil(t, info) | ||
cancel() | ||
wg.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2022 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 capture | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingcap/tiflow/pkg/leakutil" | ||
"go.uber.org/goleak" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
opts := []goleak.Option{ | ||
// TODO: temporarily ignore leaking goroutines | ||
goleak.IgnoreTopFunction("google.golang.org/grpc.(*ccBalancerWrapper).watcher"), | ||
goleak.IgnoreTopFunction("google.golang.org/grpc.(*addrConn).resetTransport"), | ||
} | ||
|
||
leakutil.SetUpLeakTest(m, opts...) | ||
} |