AB#2258: Fix flacky retry_test.go

Co-authored-by: <mp@edgeless.systems>
Co-authored-by: <pm@edgeless.systems>
This commit is contained in:
Otto Bittner 2022-08-05 17:23:17 +02:00
parent 6ef0f5d06b
commit 129caae0e4
2 changed files with 21 additions and 7 deletions

View File

@ -7,9 +7,14 @@ import (
"time"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
testclock "k8s.io/utils/clock/testing"
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
func TestDo(t *testing.T) {
testCases := map[string]struct {
cancel bool
@ -64,16 +69,15 @@ func TestDo(t *testing.T) {
defer cancel()
go func() { retrierResult <- retrier.Do(ctx) }()
if tc.cancel {
cancel()
}
for _, err := range tc.errors {
doer.errC <- err
clock.Step(retrier.interval)
}
if tc.cancel {
cancel()
}
assert.Equal(tc.wantErr, <-retrierResult)
})
}
@ -89,8 +93,13 @@ func newStubDoer() *stubDoer {
}
}
func (d *stubDoer) Do(_ context.Context) error {
return <-d.errC
func (d *stubDoer) Do(ctx context.Context) error {
select {
case <-ctx.Done():
return ctx.Err()
case err := <-d.errC:
return err
}
}
func isRetriable(err error) bool {

View File

@ -4,8 +4,13 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
func TestVerifySignature(t *testing.T) {
testCases := map[string]struct {
content []byte