Fix for already ready ksvc (#1925)

This commit is contained in:
David Simansky 2024-04-23 09:41:26 +02:00 committed by GitHub
parent da50d997de
commit 46beff542b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -366,6 +366,10 @@ func (cl *knServingClient) WaitForService(ctx context.Context, name string, wcon
} }
return err, 0 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) return waitForReady.Wait(ctx, name, service.ResourceVersion, wait.Options{Timeout: &wconfig.Timeout, ErrorWindow: &wconfig.ErrorWindow}, msgCallback)
} }

View File

@ -748,6 +748,7 @@ func TestWaitForService(t *testing.T) {
serving, client := setup() serving, client := setup()
serviceName := "test-service" serviceName := "test-service"
readyServiceName := "ready-service"
notFoundServiceName := "not-found-service" notFoundServiceName := "not-found-service"
internalErrorServiceName := "internal-error-service" internalErrorServiceName := "internal-error-service"
@ -771,6 +772,9 @@ func TestWaitForService(t *testing.T) {
case serviceName: case serviceName:
err = nil err = nil
svc = newService(serviceName) svc = newService(serviceName)
case readyServiceName:
err = nil
svc = wait.CreateTestServiceWithConditions(readyServiceName, corev1.ConditionTrue, corev1.ConditionTrue, "", "", 2)
case notFoundServiceName: case notFoundServiceName:
err = apierrors.NewNotFound(servingv1.Resource("service"), notFoundServiceName) err = apierrors.NewNotFound(servingv1.Resource("service"), notFoundServiceName)
case internalErrorServiceName: case internalErrorServiceName:
@ -790,6 +794,15 @@ func TestWaitForService(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
assert.Assert(t, duration > 0) 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) { 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{ err, duration := client.WaitForService(context.Background(), notFoundServiceName, WaitConfig{
Timeout: time.Duration(10) * time.Second, Timeout: time.Duration(10) * time.Second,