mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Fix TestCtlV3Lock/Elect flakes
waiting for a proper exit after a signal should ensure the goroutines don't leak. Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
This commit is contained in:
parent
a6997644c3
commit
eebfd15983
@ -64,7 +64,12 @@ func testElect(cx ctlCtx) {
|
||||
if err != nil {
|
||||
cx.t.Fatal(err)
|
||||
}
|
||||
defer blockAcquire.Stop()
|
||||
defer func(blockAcquire *expect.ExpectProcess) {
|
||||
err = blockAcquire.Stop()
|
||||
require.NoError(cx.t, err)
|
||||
blockAcquire.Wait()
|
||||
}(blockAcquire)
|
||||
|
||||
select {
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
case <-ch:
|
||||
@ -110,7 +115,10 @@ func ctlV3Elect(cx ctlCtx, name, proposal string, expectFailure bool) (*expect.E
|
||||
return proc, outc, err
|
||||
}
|
||||
go func() {
|
||||
s, xerr := proc.ExpectFunc(context.TODO(), func(string) bool { return true })
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
s, xerr := proc.ExpectFunc(ctx, func(string) bool { return true })
|
||||
if xerr != nil {
|
||||
if !expectFailure {
|
||||
cx.t.Errorf("expect failed (%v)", xerr)
|
||||
|
@ -69,7 +69,12 @@ func testLock(cx ctlCtx) {
|
||||
if err != nil {
|
||||
cx.t.Fatal(err)
|
||||
}
|
||||
defer blockAcquire.Stop()
|
||||
defer func(blockAcquire *expect.ExpectProcess) {
|
||||
err = blockAcquire.Stop()
|
||||
require.NoError(cx.t, err)
|
||||
blockAcquire.Wait()
|
||||
}(blockAcquire)
|
||||
|
||||
select {
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
case <-ch:
|
||||
@ -130,7 +135,10 @@ func ctlV3Lock(cx ctlCtx, name string) (*expect.ExpectProcess, <-chan string, er
|
||||
return proc, outc, err
|
||||
}
|
||||
go func() {
|
||||
s, xerr := proc.ExpectFunc(context.TODO(), func(string) bool { return true })
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
s, xerr := proc.ExpectFunc(ctx, func(string) bool { return true })
|
||||
if xerr != nil {
|
||||
require.ErrorContains(cx.t, xerr, "Error: context canceled")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user