diff options
author | Fabricio Voznika <fvoznika@google.com> | 2018-07-25 17:36:52 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-07-25 17:37:53 -0700 |
commit | e5adf42f66a3090f6124bceb5487238bf7526302 (patch) | |
tree | b6cc931ea9cf1d565dd7c79f7b16ae97deeb7df0 /runsc/test/testutil/testutil.go | |
parent | 7cd9405b9cc112ebe352af0e5f13b7b57628001b (diff) |
Replace sleeps with waits in tests - part I
PiperOrigin-RevId: 206084473
Change-Id: I44e1b64b9cdd2964357799dca27cc0cbc19ce07d
Diffstat (limited to 'runsc/test/testutil/testutil.go')
-rw-r--r-- | runsc/test/testutil/testutil.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/runsc/test/testutil/testutil.go b/runsc/test/testutil/testutil.go index c7cef9c75..721478353 100644 --- a/runsc/test/testutil/testutil.go +++ b/runsc/test/testutil/testutil.go @@ -16,6 +16,7 @@ package testutil import ( + "context" "encoding/json" "fmt" "io" @@ -24,6 +25,7 @@ import ( "path/filepath" "time" + "github.com/cenkalti/backoff" specs "github.com/opencontainers/runtime-spec/specs-go" "gvisor.googlesource.com/gvisor/runsc/boot" "gvisor.googlesource.com/gvisor/runsc/specutils" @@ -172,3 +174,11 @@ func Copy(src, dst string) error { _, err = io.Copy(out, in) return err } + +// Poll is a shorthand function to poll for something with given timeout. +func Poll(cb func() error, timeout time.Duration) error { + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + b := backoff.WithContext(backoff.NewConstantBackOff(100*time.Millisecond), ctx) + return backoff.Retry(cb, b) +} |