Skip to content

Commit

Permalink
Replace wait.PollInfinite() and wait.Poll()
Browse files Browse the repository at this point in the history
Signed-off-by: pingjiang <[email protected]>
  • Loading branch information
xiangpingjiang committed Oct 26, 2023
1 parent 00535ec commit 9332202
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/activator/net/throttler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func TestThrottlerErrorNoRevision(t *testing.T) {

// Eventually it should now fail.
var lastError error
wait.PollInfinite(10*time.Millisecond, func() (bool, error) {
wait.PollUntilContextCancel(ctx, 10*time.Millisecond, false, func(context.Context) (bool, error) {
lastError = throttler.Try(ctx, revID, func(string) error { return nil })
return lastError != nil, nil
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/queue/certificate/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package certificate

import (
"context"
"crypto/tls"
"crypto/x509"
"os"
Expand Down Expand Up @@ -70,7 +71,7 @@ func TestCertificateRotation(t *testing.T) {

// CertWatcher should return the new certificate
// Give CertWatcher some time to update the certificate
if err := wait.Poll(1*time.Second, 60*time.Second, func() (bool, error) {
if err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 60*time.Second, true, func(context.Context) (bool, error) {
c, err = cw.GetCertificate(nil)
if err != nil {
return false, err
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/autoscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func TestTargetBurstCapacity(t *testing.T) {

// Wait for two stable pods.
obsScale := 0.0
if err := wait.Poll(250*time.Millisecond, 2*cfg.StableWindow, func() (bool, error) {
if err := wait.PollUntilContextTimeout(context.Background(), 250*time.Millisecond, 2*cfg.StableWindow, true, func(context.Context) (bool, error) {
obsScale, _, err = numberOfReadyPods(ctx)
if err != nil {
return false, err
Expand All @@ -220,7 +220,7 @@ func TestTargetBurstCapacity(t *testing.T) {
// Now read the service endpoints and make sure there are 2 endpoints there.
// We poll, since network programming takes times, but the timeout is set for
// uniformness with one above.
if err := wait.Poll(250*time.Millisecond, 2*cfg.StableWindow, func() (bool, error) {
if err := wait.PollUntilContextTimeout(context.Background(), 250*time.Millisecond, 2*cfg.StableWindow, true, func(context.Context) (bool, error) {
svcEps, err := ctx.clients.KubeClient.CoreV1().Endpoints(test.ServingFlags.TestNamespace).Get(
context.Background(), ctx.resources.Revision.Name, /* revision service name is equal to revision name*/
metav1.GetOptions{})
Expand Down Expand Up @@ -375,14 +375,14 @@ func TestActivationScale(t *testing.T) {
}

// initial scale of revision
if err := wait.Poll(1*time.Second, 5*time.Minute, func() (bool, error) {
if err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 5*time.Minute, true, func(context.Context) (bool, error) {
return *resources.Revision.Status.ActualReplicas > 0, nil
}); err != nil {
t.Errorf("error: revision never had active pods")
}

// scale to zero
if err := wait.Poll(1*time.Second, 5*time.Minute, func() (bool, error) {
if err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 5*time.Minute, true, func(context.Context) (bool, error) {
resources, _ = testv1.GetResourceObjects(clients, *ctx.names)
return *resources.Revision.Status.ActualReplicas == 0, nil
}); err != nil {
Expand All @@ -406,7 +406,7 @@ func TestActivationScale(t *testing.T) {
}

// wait for revision desired replicas to equal activation scale
if err := wait.Poll(1*time.Second, 5*time.Minute, func() (bool, error) {
if err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 5*time.Minute, true, func(context.Context) (bool, error) {
resources, _ = testv1.GetResourceObjects(clients, *ctx.names)
return *resources.Revision.Status.DesiredReplicas == activationScale, nil
}); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func waitForActivatorEndpoints(ctx *TestContext) error {
wantAct int
)

if rerr := wait.Poll(250*time.Millisecond, time.Minute, func() (bool, error) {
if rerr := wait.PollUntilContextTimeout(context.Background(), 250*time.Millisecond, time.Minute, true, func(context.Context) (bool, error) {
// We need to fetch the activator endpoints at every check, since it can change.
actEps, err := ctx.clients.KubeClient.CoreV1().Endpoints(
system.Namespace()).Get(context.Background(), networking.ActivatorServiceName, metav1.GetOptions{})
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/minscale_readiness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package e2e

import (
"context"
"errors"
"fmt"
"strconv"
"testing"
Expand Down Expand Up @@ -255,9 +256,9 @@ func ensureDesiredScale(clients *test.Clients, t *testing.T, serviceName string,

return false, nil
})
if err.Error() != "context deadline exceeded" {
if !errors.Is(err, context.DeadlineExceeded) {
t.Log("PollError =", err)
}

return latestReady, err.Error() == "context deadline exceeded"
return latestReady, errors.Is(err, context.DeadlineExceeded)
}

0 comments on commit 9332202

Please sign in to comment.