mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-01 14:05:39 +00:00
71029cea2d
This updates all source files to use a new standard header for copyright and license declaration. Notably, copyright no longer includes a date, and we now use the standard SPDX-License-Identifier header. This commit was done almost entirely mechanically with perl, and then some minimal manual fixes. Updates #6865 Signed-off-by: Will Norris <will@tailscale.com>
31 lines
734 B
Go
31 lines
734 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Package tstest provides utilities for use in unit tests.
|
|
package tstest
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"tailscale.com/logtail/backoff"
|
|
"tailscale.com/types/logger"
|
|
)
|
|
|
|
// WaitFor retries try for up to maxWait.
|
|
// It returns nil once try returns nil the first time.
|
|
// If maxWait passes without success, it returns try's last error.
|
|
func WaitFor(maxWait time.Duration, try func() error) error {
|
|
bo := backoff.NewBackoff("wait-for", logger.Discard, maxWait/4)
|
|
deadline := time.Now().Add(maxWait)
|
|
var err error
|
|
for time.Now().Before(deadline) {
|
|
err = try()
|
|
if err == nil {
|
|
break
|
|
}
|
|
bo.BackOff(context.Background(), err)
|
|
}
|
|
return err
|
|
}
|