|
|
@ -8,6 +8,7 @@ import (
|
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/tal-tech/go-zero/core/contextx"
|
|
|
|
"github.com/tal-tech/go-zero/core/contextx"
|
|
|
|
|
|
|
|
"github.com/tal-tech/go-zero/core/lang"
|
|
|
|
"github.com/tal-tech/go-zero/core/logx"
|
|
|
|
"github.com/tal-tech/go-zero/core/logx"
|
|
|
|
"github.com/tal-tech/go-zero/core/stringx"
|
|
|
|
"github.com/tal-tech/go-zero/core/stringx"
|
|
|
|
"go.etcd.io/etcd/clientv3"
|
|
|
|
"go.etcd.io/etcd/clientv3"
|
|
|
@ -202,11 +203,13 @@ func TestClusterWatch_RespFailures(t *testing.T) {
|
|
|
|
restore := setMockClient(cli)
|
|
|
|
restore := setMockClient(cli)
|
|
|
|
defer restore()
|
|
|
|
defer restore()
|
|
|
|
ch := make(chan clientv3.WatchResponse)
|
|
|
|
ch := make(chan clientv3.WatchResponse)
|
|
|
|
cli.EXPECT().Watch(gomock.Any(), "any/", gomock.Any()).Return(ch)
|
|
|
|
cli.EXPECT().Watch(gomock.Any(), "any/", gomock.Any()).Return(ch).AnyTimes()
|
|
|
|
cli.EXPECT().Ctx().Return(context.Background()).AnyTimes()
|
|
|
|
cli.EXPECT().Ctx().Return(context.Background()).AnyTimes()
|
|
|
|
c := new(cluster)
|
|
|
|
c := new(cluster)
|
|
|
|
|
|
|
|
c.done = make(chan lang.PlaceholderType)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
ch <- resp
|
|
|
|
ch <- resp
|
|
|
|
|
|
|
|
close(c.done)
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
c.watch(cli, "any")
|
|
|
|
c.watch(cli, "any")
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -220,11 +223,13 @@ func TestClusterWatch_CloseChan(t *testing.T) {
|
|
|
|
restore := setMockClient(cli)
|
|
|
|
restore := setMockClient(cli)
|
|
|
|
defer restore()
|
|
|
|
defer restore()
|
|
|
|
ch := make(chan clientv3.WatchResponse)
|
|
|
|
ch := make(chan clientv3.WatchResponse)
|
|
|
|
cli.EXPECT().Watch(gomock.Any(), "any/", gomock.Any()).Return(ch)
|
|
|
|
cli.EXPECT().Watch(gomock.Any(), "any/", gomock.Any()).Return(ch).AnyTimes()
|
|
|
|
cli.EXPECT().Ctx().Return(context.Background()).AnyTimes()
|
|
|
|
cli.EXPECT().Ctx().Return(context.Background()).AnyTimes()
|
|
|
|
c := new(cluster)
|
|
|
|
c := new(cluster)
|
|
|
|
|
|
|
|
c.done = make(chan lang.PlaceholderType)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
close(ch)
|
|
|
|
close(ch)
|
|
|
|
|
|
|
|
close(c.done)
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
c.watch(cli, "any")
|
|
|
|
c.watch(cli, "any")
|
|
|
|
}
|
|
|
|
}
|
|
|
|