Merge pull request #14798 from tjungblu/fix_locking_tests

Fix TestCtlV3Lock/Elect flakes
This commit is contained in:
Marek Siarkowicz 2022-11-17 15:40:47 +01:00 committed by GitHub
commit 9b3bfcdfeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -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)

View File

@ -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")
}