Skip to content

Commit

Permalink
make lint
Browse files Browse the repository at this point in the history
Signed-off-by: joccau <zak.zhao@pingcap.cn>
  • Loading branch information
joccau committed Aug 27, 2024
1 parent 28a2c33 commit 831f8b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pkg/owner/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,9 @@ func GetOwnerOpValue(ctx context.Context, etcdCli *clientv3.Client, ownerPath, l
return op, errors.Trace(err)
}

// WatchOwner watches the ownerKey. It's exported for testing only.
func WatchOwner(m Manager, ctx context.Context, etcdSession *concurrency.Session, key string, ownerRevision int64) {
// WatchOwnerForTest watches the ownerKey.
// This function is used to test watchOwner().
func WatchOwnerForTest(ctx context.Context, m Manager, etcdSession *concurrency.Session, key string, ownerRevision int64) {
if ownerManager, ok := m.(*ownerManager); ok {
ownerManager.watchOwner(ctx, etcdSession, key, ownerRevision)
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/owner/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,12 @@ func TestWatchOwner(t *testing.T) {
require.NoError(t, err)

// watch the ownerKey with the `DELETE` event.
ctx2, _ := context.WithTimeout(ctx, time.Millisecond*300)
ctx2, cancel2 := context.WithTimeout(ctx, time.Millisecond*300)
defer cancel2()
watchDone := make(chan bool)
watched := false
go func() {
owner.WatchOwner(ownerManager, ctx2, session, ownerKey, createRevision)
owner.WatchOwnerForTest(ctx2, ownerManager, session, ownerKey, createRevision)
watchDone <- true
}()

Expand All @@ -345,15 +346,16 @@ func TestWatchOwner(t *testing.T) {
require.False(t, watched)

// delete the owner, and can watch the event.
g(client, DDLOwnerKey)
deleteLeader(client, DDLOwnerKey)
require.NoError(t, err)
watched = <-watchDone
require.True(t, watched)

// the ownerKey has been deleted, watch ownerKey again, it can be watched.
watched = false
ctx3, cancel3 := context.WithTimeout(ctx, time.Millisecond*300)
defer cancel3()
go func() {
owner.WatchOwner(ownerManager, ctx2, session, ownerKey, createRevision)
owner.WatchOwnerForTest(ctx3, ownerManager, session, ownerKey, createRevision)
watchDone <- true
}()

Expand Down

0 comments on commit 831f8b6

Please sign in to comment.