aboutsummaryrefslogtreecommitdiffstats
path: root/client/go
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2024-06-05 15:58:38 +0200
committerMartin Polden <mpolden@mpolden.no>2024-06-05 16:01:20 +0200
commita525bf8d9bfee41aef63179c1ee4f37e344814e3 (patch)
tree4bc469bfa8d889dedfb7b56eaea970c79bd17f11 /client/go
parentb8f472d0e7d4e9349db02fbbb5294174a0f520a3 (diff)
Use a short default wait for cloud deployment
Diffstat (limited to 'client/go')
-rw-r--r--client/go/internal/cli/cmd/deploy.go7
-rw-r--r--client/go/internal/cli/cmd/deploy_test.go23
-rw-r--r--client/go/internal/mock/http.go2
3 files changed, 31 insertions, 1 deletions
diff --git a/client/go/internal/cli/cmd/deploy.go b/client/go/internal/cli/cmd/deploy.go
index 9ae6676bc17..8372f6691dd 100644
--- a/client/go/internal/cli/cmd/deploy.go
+++ b/client/go/internal/cli/cmd/deploy.go
@@ -59,7 +59,6 @@ $ vespa deploy -t cloud -z perf.aws-us-east-1c`,
if err != nil {
return err
}
- timeout := time.Duration(waitSecs) * time.Second
opts := vespa.DeploymentOptions{ApplicationPackage: pkg, Target: target}
if versionArg != "" {
version, err := version.Parse(versionArg)
@@ -73,6 +72,12 @@ $ vespa deploy -t cloud -z perf.aws-us-east-1c`,
return err
}
}
+ if opts.Target.IsCloud() && waitSecs == 0 && !cmd.PersistentFlags().Changed("wait") {
+ // If --wait is not explicitly given, we always wait a few seconds in Cloud to catch fast failures, e.g.
+ // invalid application package
+ waitSecs = 2
+ }
+ timeout := time.Duration(waitSecs) * time.Second
waiter := cli.waiter(timeout)
if _, err := waiter.DeployService(target); err != nil {
return err
diff --git a/client/go/internal/cli/cmd/deploy_test.go b/client/go/internal/cli/cmd/deploy_test.go
index 4e32b9bbd60..9a046a984f6 100644
--- a/client/go/internal/cli/cmd/deploy_test.go
+++ b/client/go/internal/cli/cmd/deploy_test.go
@@ -62,6 +62,29 @@ Hint: Pass --add-cert to use the certificate of the current application
assert.Contains(t, stdout.String(), "Success: Triggered deployment")
}
+func TestDeployCloudDefaultWait(t *testing.T) {
+ pkgDir := filepath.Join(t.TempDir(), "app")
+ createApplication(t, pkgDir, false, false)
+
+ cli, stdout, _ := newTestCLI(t, "CI=true")
+ httpClient := &mock.HTTPClient{}
+ httpClient.NextResponseString(200, `ok`)
+ httpClient.NextResponseString(200, `ok`)
+ httpClient.NextResponseString(200, `{"active": false, "status": "success"}`)
+ httpClient.NextResponseString(200, `{"endpoints": [{"url": "http://example.com", "scope": "zone", "cluster": "default"}]}`)
+ cli.httpClient = httpClient
+
+ app := vespa.ApplicationID{Tenant: "t1", Application: "a1", Instance: "i1"}
+ assert.Nil(t, cli.Run("config", "set", "application", app.String()))
+ assert.Nil(t, cli.Run("config", "set", "target", "cloud"))
+ assert.Nil(t, cli.Run("auth", "api-key"))
+ assert.Nil(t, cli.Run("auth", "cert", pkgDir))
+
+ require.Nil(t, cli.Run("deploy", pkgDir))
+ assert.Contains(t, stdout.String(), "Success: Triggered deployment")
+ assert.True(t, httpClient.Consumed())
+}
+
func TestDeployWait(t *testing.T) {
cli, stdout, _ := newTestCLI(t)
client := &mock.HTTPClient{}
diff --git a/client/go/internal/mock/http.go b/client/go/internal/mock/http.go
index 2fbaa85ecca..48835dd3338 100644
--- a/client/go/internal/mock/http.go
+++ b/client/go/internal/mock/http.go
@@ -56,6 +56,8 @@ func (c *HTTPClient) NextResponseError(err error) {
c.nextErrors = append(c.nextErrors, err)
}
+func (c *HTTPClient) Consumed() bool { return len(c.nextResponses) == 0 }
+
func (c *HTTPClient) Do(request *http.Request, timeout time.Duration) (*http.Response, error) {
c.LastRequest = request
if len(c.nextErrors) > 0 {