Move locks on watch to allow testing blocking

pull/6/head
Clayton Coleman 2015-01-07 10:36:59 -05:00
parent 31fc19efe9
commit 880ecef6fe
1 changed files with 3 additions and 1 deletions

View File

@ -131,7 +131,7 @@ func (f *FakeEtcdClient) Get(key string, sort, recursive bool) (*etcd.Response,
} }
return &etcd.Response{}, EtcdErrorNotFound return &etcd.Response{}, EtcdErrorNotFound
} }
f.t.Logf("returning %v: %v %#v", key, result.R, result.E) f.t.Logf("returning %v: %#v %#v", key, result.R, result.E)
return result.R, result.E return result.R, result.E
} }
@ -262,6 +262,7 @@ func (f *FakeEtcdClient) WaitForWatchCompletion() {
} }
func (f *FakeEtcdClient) Watch(prefix string, waitIndex uint64, recursive bool, receiver chan *etcd.Response, stop chan bool) (*etcd.Response, error) { func (f *FakeEtcdClient) Watch(prefix string, waitIndex uint64, recursive bool, receiver chan *etcd.Response, stop chan bool) (*etcd.Response, error) {
f.Mutex.Lock()
if f.WatchImmediateError != nil { if f.WatchImmediateError != nil {
return nil, f.WatchImmediateError return nil, f.WatchImmediateError
} }
@ -273,6 +274,7 @@ func (f *FakeEtcdClient) Watch(prefix string, waitIndex uint64, recursive bool,
defer close(injectedError) defer close(injectedError)
f.WatchInjectError = injectedError f.WatchInjectError = injectedError
f.Mutex.Unlock()
if receiver == nil { if receiver == nil {
return f.Get(prefix, false, recursive) return f.Get(prefix, false, recursive)
} else { } else {