-
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.
capture(ticdc): fix the problem that openapi is blocked when pd is ab…
- Loading branch information
1 parent
4091e2c
commit 06db40b
Showing
4 changed files
with
114 additions
and
36 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
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,62 @@ | ||
// 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 ( | ||
"context" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/pingcap/tiflow/pkg/etcd" | ||
"github.com/stretchr/testify/require" | ||
"go.etcd.io/etcd/clientv3" | ||
) | ||
|
||
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) | ||
etcdCli, err := clientv3.New(clientv3.Config{ | ||
Endpoints: []string{clientURL.String()}, | ||
Context: ctx, | ||
DialTimeout: 3 * time.Second, | ||
}) | ||
require.NoError(t, err) | ||
client := etcd.NewCDCEtcdClient(ctx, etcdCli) | ||
// Close the client before the test function exits to prevent possible | ||
// ctx leaks. | ||
// Ref: https://github.com/grpc/grpc-go/blob/master/stream.go#L229 | ||
defer client.Close() | ||
|
||
cp := NewCapture4Test() | ||
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
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