From 805a96d7ba78762a3bb96bb1cc9e32ccc569437a Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Fri, 24 Jul 2020 15:54:16 -0700 Subject: Speed up iptables tests //test/iptables:iptables_test runs 30 seconds faster on my machine. * Using contexts instead of many smaller timeouts makes the tests less likely to flake and removes unnecessary complexity. * We also use context to properly shut down concurrent goroutines and the test container. * Container logs are always logged. --- pkg/test/testutil/testutil.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pkg') diff --git a/pkg/test/testutil/testutil.go b/pkg/test/testutil/testutil.go index 64c292698..1580527b5 100644 --- a/pkg/test/testutil/testutil.go +++ b/pkg/test/testutil/testutil.go @@ -316,6 +316,11 @@ func Copy(src, dst string) error { func Poll(cb func() error, timeout time.Duration) error { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() + return PollContext(ctx, cb) +} + +// PollContext is like Poll, but takes a context instead of a timeout. +func PollContext(ctx context.Context, cb func() error) error { b := backoff.WithContext(backoff.NewConstantBackOff(100*time.Millisecond), ctx) return backoff.Retry(cb, b) } -- cgit v1.2.3