Skip to content
Snippets Groups Projects
Commit dfa8267f authored by scott's avatar scott
Browse files

sync watch unit goroutine

parent 3349096c
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -395,19 +395,22 @@ func (s *KubernetesClientTestSuite) TestClientWatchPrefix() { ...@@ -395,19 +395,22 @@ func (s *KubernetesClientTestSuite) TestClientWatchPrefix() {
go func() { go func() {
defer wg.Done()
wc, err := client.WatchWithPrefix(prefix) wc, err := client.WatchWithPrefix(prefix)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
wg.Done()
for e := range wc { for e := range wc {
t.Logf("got event %v k %s v %s", e.EventType, e.Key, e.Value) t.Logf("got event %v k %s v %s", e.EventType, e.Key, e.Value)
} }
}() }()
// must wait the watch goroutine work
wg.Wait()
for _, tc := range tests { for _, tc := range tests {
k := tc.input.k k := tc.input.k
...@@ -419,7 +422,6 @@ func (s *KubernetesClientTestSuite) TestClientWatchPrefix() { ...@@ -419,7 +422,6 @@ func (s *KubernetesClientTestSuite) TestClientWatchPrefix() {
} }
client.Close() client.Close()
wg.Wait()
} }
func (s *KubernetesClientTestSuite) TestNewClient() { func (s *KubernetesClientTestSuite) TestNewClient() {
...@@ -444,12 +446,11 @@ func (s *KubernetesClientTestSuite) TestClientWatch() { ...@@ -444,12 +446,11 @@ func (s *KubernetesClientTestSuite) TestClientWatch() {
go func() { go func() {
defer wg.Done()
wc, err := client.Watch(prefix) wc, err := client.Watch(prefix)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
wg.Done()
for e := range wc { for e := range wc {
t.Logf("got event %v k %s v %s", e.EventType, e.Key, e.Value) t.Logf("got event %v k %s v %s", e.EventType, e.Key, e.Value)
...@@ -457,6 +458,9 @@ func (s *KubernetesClientTestSuite) TestClientWatch() { ...@@ -457,6 +458,9 @@ func (s *KubernetesClientTestSuite) TestClientWatch() {
}() }()
// must wait the watch goroutine already start the watch goroutine
wg.Wait()
for _, tc := range tests { for _, tc := range tests {
k := tc.input.k k := tc.input.k
...@@ -468,7 +472,6 @@ func (s *KubernetesClientTestSuite) TestClientWatch() { ...@@ -468,7 +472,6 @@ func (s *KubernetesClientTestSuite) TestClientWatch() {
} }
client.Close() client.Close()
wg.Wait()
} }
func TestKubernetesClient(t *testing.T) { func TestKubernetesClient(t *testing.T) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment