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

test(master/shardddl): migrate test-infra to testify for master/shardddl pkg #4893

Merged
merged 12 commits into from
Mar 16, 2022
14 changes: 8 additions & 6 deletions dm/dm/master/shardddl/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
package shardddl

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

"github.com/stretchr/testify/require"

"github.com/pingcap/tiflow/dm/pkg/shardddl/pessimism"
)

func (t *testPessimist) TestInfoSlice(c *C) {
func TestInfoSlice(t *testing.T) {
var (
task = "task"
source1 = "mysql-replica-1"
Expand All @@ -35,8 +37,8 @@ func (t *testPessimist) TestInfoSlice(c *C) {
)

ifs := pessimismInfoMapToSlice(ifm)
c.Assert(ifs, HasLen, 3)
c.Assert(ifs[0], DeepEquals, ifm[source1])
c.Assert(ifs[1], DeepEquals, ifm[source2])
c.Assert(ifs[2], DeepEquals, ifm[source3])
require.Len(t, ifs, 3)
require.Equal(t, ifm[source1], ifs[0])
require.Equal(t, ifm[source2], ifs[1])
require.Equal(t, ifm[source3], ifs[2])
}
8 changes: 5 additions & 3 deletions dm/dm/master/shardddl/optimist.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ func (o *Optimist) Start(pCtx context.Context, etcdCli *clientv3.Client) error {
// Close closes the Optimist instance.
func (o *Optimist) Close() {
o.mu.Lock()
defer o.mu.Unlock()

if o.closed {
o.mu.Unlock()
return
}

Expand All @@ -106,8 +105,11 @@ func (o *Optimist) Close() {
o.cancel = nil
}

o.wg.Wait()
o.closed = true // closed now.
o.mu.Unlock()
// unlock before wg.Wait() to avoid deadlock because other goroutines acquire the lock.
// such as https://github.com/pingcap/tiflow/blob/92fc4c4/dm/dm/master/shardddl/optimist.go#L686
o.wg.Wait()
o.logger.Info("the shard DDL optimist has closed")
}

Expand Down
Loading