Skip to content

Commit

Permalink
Fix for already ready ksvc (#1925)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsimansk authored Apr 23, 2024
1 parent da50d99 commit 46beff5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/serving/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ func (cl *knServingClient) WaitForService(ctx context.Context, name string, wcon
}
return err, 0
}
// In case of standalone wait command, it can be executed on already ready ksvc.
if service.IsReady() {
return nil, 0
}
return waitForReady.Wait(ctx, name, service.ResourceVersion, wait.Options{Timeout: &wconfig.Timeout, ErrorWindow: &wconfig.ErrorWindow}, msgCallback)
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/serving/v1/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ func TestWaitForService(t *testing.T) {
serving, client := setup()

serviceName := "test-service"
readyServiceName := "ready-service"
notFoundServiceName := "not-found-service"
internalErrorServiceName := "internal-error-service"

Expand All @@ -771,6 +772,9 @@ func TestWaitForService(t *testing.T) {
case serviceName:
err = nil
svc = newService(serviceName)
case readyServiceName:
err = nil
svc = wait.CreateTestServiceWithConditions(readyServiceName, corev1.ConditionTrue, corev1.ConditionTrue, "", "", 2)
case notFoundServiceName:
err = apierrors.NewNotFound(servingv1.Resource("service"), notFoundServiceName)
case internalErrorServiceName:
Expand All @@ -790,6 +794,15 @@ func TestWaitForService(t *testing.T) {
assert.NilError(t, err)
assert.Assert(t, duration > 0)
})
t.Run("wait on a service that is already ready with success", func(t *testing.T) {
err, duration := client.WaitForService(context.Background(), readyServiceName, WaitConfig{
Timeout: time.Duration(10) * time.Second,
ErrorWindow: time.Duration(2) * time.Second,
}, wait.NoopMessageCallback())
assert.NilError(t, err)
println("duration:", duration)
assert.Assert(t, duration == 0)
})
t.Run("wait on a service to become ready with not found error", func(t *testing.T) {
err, duration := client.WaitForService(context.Background(), notFoundServiceName, WaitConfig{
Timeout: time.Duration(10) * time.Second,
Expand Down

0 comments on commit 46beff5

Please sign in to comment.