mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
e2e: fix race in etcdctl watch tests
This commit is contained in:
parent
7960bd8690
commit
6bbb916b47
@ -172,23 +172,18 @@ func testCtlV2Watch(t *testing.T, cfg *etcdProcessClusterConfig, noSync bool) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
key, value := "foo", "bar"
|
key, value := "foo", "bar"
|
||||||
done, errChan := make(chan struct{}, 1), make(chan error, 1)
|
errc := etcdctlWatch(epc, key, value, noSync)
|
||||||
|
|
||||||
go etcdctlWatch(epc, key, value, noSync, done, errChan)
|
|
||||||
|
|
||||||
if err := etcdctlSet(epc, key, value, noSync); err != nil {
|
if err := etcdctlSet(epc, key, value, noSync); err != nil {
|
||||||
t.Fatalf("failed set (%v)", err)
|
t.Fatalf("failed set (%v)", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case err := <-errc:
|
||||||
return
|
if err != nil {
|
||||||
case err := <-errChan:
|
|
||||||
t.Fatalf("failed watch (%v)", err)
|
t.Fatalf("failed watch (%v)", err)
|
||||||
|
}
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
// TODO: 'watch' sometimes times out in Semaphore CI environment
|
t.Fatalf("watch timed out")
|
||||||
// but works fine in every other environments
|
|
||||||
t.Logf("[WARNING] watch timed out!")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,11 +235,11 @@ func etcdctlLs(clus *etcdProcessCluster, key string, noSync bool) error {
|
|||||||
return spawnWithExpect(cmdArgs, key)
|
return spawnWithExpect(cmdArgs, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func etcdctlWatch(clus *etcdProcessCluster, key, value string, noSync bool, done chan struct{}, errChan chan error) {
|
func etcdctlWatch(clus *etcdProcessCluster, key, value string, noSync bool) <-chan error {
|
||||||
cmdArgs := append(etcdctlPrefixArgs(clus, noSync), "watch", key)
|
cmdArgs := append(etcdctlPrefixArgs(clus, noSync), "watch", "--after-index 1", key)
|
||||||
if err := spawnWithExpect(cmdArgs, value); err != nil {
|
errc := make(chan error, 1)
|
||||||
errChan <- err
|
go func() {
|
||||||
return
|
errc <- spawnWithExpect(cmdArgs, value)
|
||||||
}
|
}()
|
||||||
done <- struct{}{}
|
return errc
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user