summaryrefslogtreecommitdiffhomepage
path: root/pkg/test
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2020-07-24 15:54:16 -0700
committerKevin Krakauer <krakauer@google.com>2020-08-10 17:50:01 -0700
commit805a96d7ba78762a3bb96bb1cc9e32ccc569437a (patch)
treea31541352b52c28488f979bce3faed50be30f3b4 /pkg/test
parent0a8ae4b32f0dbc0b2a84c3f07c8c98e855a8f5fa (diff)
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.
Diffstat (limited to 'pkg/test')
-rw-r--r--pkg/test/testutil/testutil.go5
1 files changed, 5 insertions, 0 deletions
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)
}