Replace usages of deprecated funcs from the wait pkg
This commit is contained in:
parent
4756df08cb
commit
a1a99b9eeb
@ -486,7 +486,7 @@ func TestController(t *testing.T) {
|
|||||||
authenticated bool
|
authenticated bool
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
_ = wait.PollImmediate(10*time.Millisecond, 5*time.Second, func() (bool, error) {
|
_ = wait.PollUntilContextTimeout(context.Background(), 10*time.Millisecond, 5*time.Second, true, func(ctx context.Context) (bool, error) {
|
||||||
rsp, authenticated, err = cachedAuthenticator.AuthenticateToken(context.Background(), jwt)
|
rsp, authenticated, err = cachedAuthenticator.AuthenticateToken(context.Background(), jwt)
|
||||||
return !isNotInitialized(err), nil
|
return !isNotInitialized(err), nil
|
||||||
})
|
})
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
package dynamiccert
|
package dynamiccert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"net"
|
"net"
|
||||||
@ -194,7 +195,7 @@ func TestProviderWithDynamicServingCertificateController(t *testing.T) {
|
|||||||
var lastTLSConfig *tls.Config
|
var lastTLSConfig *tls.Config
|
||||||
|
|
||||||
// it will take some time for the controller to catch up
|
// it will take some time for the controller to catch up
|
||||||
err = wait.PollImmediate(time.Second, 30*time.Second, func() (bool, error) {
|
err = wait.PollUntilContextTimeout(context.Background(), time.Second, 30*time.Second, true, func(ctx context.Context) (bool, error) {
|
||||||
actualTLSConfig, err := tlsConfig.GetConfigForClient(&tls.ClientHelloInfo{ServerName: "force-standard-sni"})
|
actualTLSConfig, err := tlsConfig.GetConfigForClient(&tls.ClientHelloInfo{ServerName: "force-standard-sni"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
// Copyright 2021-2022 the Pinniped contributors. All Rights Reserved.
|
// Copyright 2021-2023 the Pinniped contributors. All Rights Reserved.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package testlib
|
package testlib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -88,7 +87,7 @@ func RequireEventually(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Run the check until it completes with no assertion failures.
|
// Run the check until it completes with no assertion failures.
|
||||||
waitErr := wait.PollImmediate(tick, waitFor, func() (bool, error) {
|
waitErr := wait.PollUntilContextTimeout(context.Background(), tick, waitFor, true, func(ctx context.Context) (bool, error) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
attempts++
|
attempts++
|
||||||
|
|
||||||
@ -133,7 +132,10 @@ func RequireEventuallyWithoutError(
|
|||||||
msgAndArgs ...interface{},
|
msgAndArgs ...interface{},
|
||||||
) {
|
) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
require.NoError(t, wait.PollImmediate(tick, waitFor, f), msgAndArgs...)
|
// This previously used wait.PollImmediate (now deprecated), which did not take a ctx arg in the func.
|
||||||
|
// Hide this detail from the callers for now to keep the old signature.
|
||||||
|
fWithCtx := func(ctx context.Context) (bool, error) { return f() }
|
||||||
|
require.NoError(t, wait.PollUntilContextTimeout(context.Background(), tick, waitFor, true, fWithCtx), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequireNeverWithoutError is similar to require.Never() except that it also allows the caller to
|
// RequireNeverWithoutError is similar to require.Never() except that it also allows the caller to
|
||||||
@ -147,9 +149,11 @@ func RequireNeverWithoutError(
|
|||||||
msgAndArgs ...interface{},
|
msgAndArgs ...interface{},
|
||||||
) {
|
) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
err := wait.PollImmediate(tick, waitFor, f)
|
// This previously used wait.PollImmediate (now deprecated), which did not take a ctx arg in the func.
|
||||||
isWaitTimeout := errors.Is(err, wait.ErrWaitTimeout)
|
// Hide this detail from the callers for now to keep the old signature.
|
||||||
if err != nil && !isWaitTimeout {
|
fWithCtx := func(ctx context.Context) (bool, error) { return f() }
|
||||||
|
err := wait.PollUntilContextTimeout(context.Background(), tick, waitFor, true, fWithCtx)
|
||||||
|
if err != nil && !wait.Interrupted(err) {
|
||||||
require.NoError(t, err, msgAndArgs...) // this will fail and throw the right error message
|
require.NoError(t, err, msgAndArgs...) // this will fail and throw the right error message
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user