Fix race condition in TestClient_WatchList and TestClient_WatchGet
This commit is contained in:
parent
2379b822ad
commit
114ee0755a
|
@ -244,6 +244,7 @@ func TestClient_WatchGet(t *testing.T) {
|
||||||
|
|
||||||
// Put the key
|
// Put the key
|
||||||
value := []byte("test")
|
value := []byte("test")
|
||||||
|
doneCh := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
kv := c.KV()
|
kv := c.KV()
|
||||||
|
|
||||||
|
@ -252,6 +253,7 @@ func TestClient_WatchGet(t *testing.T) {
|
||||||
if _, err := kv.Put(p, nil); err != nil {
|
if _, err := kv.Put(p, nil); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
doneCh <- struct{}{}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Get should work
|
// Get should work
|
||||||
|
@ -272,6 +274,9 @@ func TestClient_WatchGet(t *testing.T) {
|
||||||
if meta2.LastIndex <= meta.LastIndex {
|
if meta2.LastIndex <= meta.LastIndex {
|
||||||
t.Fatalf("unexpected value: %#v", meta2)
|
t.Fatalf("unexpected value: %#v", meta2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Block until put finishes to avoid a race between it and deferred s.Stop()
|
||||||
|
<-doneCh
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_WatchList(t *testing.T) {
|
func TestClient_WatchList(t *testing.T) {
|
||||||
|
@ -297,6 +302,7 @@ func TestClient_WatchList(t *testing.T) {
|
||||||
|
|
||||||
// Put the key
|
// Put the key
|
||||||
value := []byte("test")
|
value := []byte("test")
|
||||||
|
doneCh := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
kv := c.KV()
|
kv := c.KV()
|
||||||
|
|
||||||
|
@ -305,6 +311,7 @@ func TestClient_WatchList(t *testing.T) {
|
||||||
if _, err := kv.Put(p, nil); err != nil {
|
if _, err := kv.Put(p, nil); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
doneCh <- struct{}{}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Get should work
|
// Get should work
|
||||||
|
@ -326,6 +333,8 @@ func TestClient_WatchList(t *testing.T) {
|
||||||
t.Fatalf("unexpected value: %#v", meta2)
|
t.Fatalf("unexpected value: %#v", meta2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Block until put finishes to avoid a race between it and deferred s.Stop()
|
||||||
|
<-doneCh
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_Keys_DeleteRecurse(t *testing.T) {
|
func TestClient_Keys_DeleteRecurse(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue