-
Notifications
You must be signed in to change notification settings - Fork 0
fix(serverless): show build status while deploy --wait polls #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import ( | |
| "net/http/httptest" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/google/uuid" | ||
| serverlessapi "github.com/runware/runware-cli/internal/api/serverless" | ||
|
|
@@ -306,6 +307,82 @@ func TestValidateUpdateDeployFlags(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestDeployWaitMessage(t *testing.T) { | ||
| if got := deployWaitMessage(testAppID, "initializing", ""); got != "Waiting for application my-app (initializing)..." { | ||
| t.Fatalf("no build: %q", got) | ||
| } | ||
| if got := deployWaitMessage(testAppID, "initializing", "building"); got != "Waiting for application my-app (initializing, build building)..." { | ||
| t.Fatalf("building: %q", got) | ||
| } | ||
| } | ||
|
|
||
| func TestWaitForAppDeploy_ReportsBuildStatus(t *testing.T) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (non-blocking): The PR says "A build list that cannot be read does not fail the wait", but no test covers it. Add a case where
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed: TestWaitForAppDeploy_ContinuesWhenBuildsFail covers a 500 from /builds; the wait still returns the active app with the no-build message. |
||
| var gets int | ||
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| w.Header().Set("Content-Type", "application/json") | ||
| if strings.Contains(r.URL.Path, "/builds") { | ||
| _, _ = w.Write([]byte(`{"data":[{"id":"33333333-3333-3333-3333-333333333333","status":"building","phases":[]}]}`)) | ||
| return | ||
| } | ||
| gets++ | ||
| status := string(serverlessapi.AppStatusInitializing) | ||
| if gets > 1 { | ||
| status = string(serverlessapi.AppStatusActive) | ||
| } | ||
| _, _ = w.Write([]byte(`{"appId":"` + testAppID + `","appName":"My App","status":"` + status + `","configuration":{"maxWorkers":1,"idleTtlSecs":60,"scalingDelaySecs":10,"computeType":"gpu","gpuType":"h100"},"environmentVariables":[],"secrets":[],"createdAt":"2026-07-30T12:00:00Z","updatedAt":"2026-07-30T12:00:00Z"}`)) | ||
| })) | ||
| defer srv.Close() | ||
|
|
||
| var seen []string | ||
| client := serverlessapi.NewClient("test-key", srv.URL, slog.Default()) | ||
| app, err := waitForAppDeploy(context.Background(), client, testAppID, time.Millisecond, func(appStatus, buildStatus string) { | ||
| seen = append(seen, deployWaitMessage(testAppID, appStatus, buildStatus)) | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("waitForAppDeploy: %v", err) | ||
| } | ||
| if app.Status != serverlessapi.AppStatusActive { | ||
| t.Fatalf("status = %s", app.Status) | ||
| } | ||
| if len(seen) != 1 || seen[0] != "Waiting for application my-app (initializing, build building)..." { | ||
| t.Fatalf("reports = %#v", seen) | ||
| } | ||
| } | ||
|
|
||
| func TestWaitForAppDeploy_ContinuesWhenBuildsFail(t *testing.T) { | ||
| var gets int | ||
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| if strings.Contains(r.URL.Path, "/builds") { | ||
| w.WriteHeader(http.StatusInternalServerError) | ||
| _, _ = w.Write([]byte(`{"error":"unavailable"}`)) | ||
| return | ||
| } | ||
| w.Header().Set("Content-Type", "application/json") | ||
| gets++ | ||
| status := string(serverlessapi.AppStatusInitializing) | ||
| if gets > 1 { | ||
| status = string(serverlessapi.AppStatusActive) | ||
| } | ||
| _, _ = w.Write([]byte(`{"appId":"` + testAppID + `","appName":"My App","status":"` + status + `","configuration":{"maxWorkers":1,"idleTtlSecs":60,"scalingDelaySecs":10,"computeType":"gpu","gpuType":"h100"},"environmentVariables":[],"secrets":[],"createdAt":"2026-07-30T12:00:00Z","updatedAt":"2026-07-30T12:00:00Z"}`)) | ||
| })) | ||
| defer srv.Close() | ||
|
|
||
| var seen []string | ||
| client := serverlessapi.NewClient("test-key", srv.URL, slog.Default()) | ||
| app, err := waitForAppDeploy(context.Background(), client, testAppID, time.Millisecond, func(appStatus, buildStatus string) { | ||
| seen = append(seen, deployWaitMessage(testAppID, appStatus, buildStatus)) | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("waitForAppDeploy: %v", err) | ||
| } | ||
| if app.Status != serverlessapi.AppStatusActive { | ||
| t.Fatalf("status = %s", app.Status) | ||
| } | ||
| if len(seen) != 1 || seen[0] != "Waiting for application my-app (initializing)..." { | ||
| t.Fatalf("reports = %#v", seen) | ||
| } | ||
| } | ||
|
|
||
| func TestAppFailedErr(t *testing.T) { | ||
| if err := appFailedErr(context.Background(), nil, nil); err != nil { | ||
| t.Fatalf("nil app: %v", err) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (non-blocking):
waitForAppDeploycopies the poll loop ofserverlessapi.Client.WaitApp, andWaitAppnow has no caller outside its tests. Add a per-poll callback toWaitAppand keep only the build lookup here; this also removes the second hard-coded2 * time.Secondnext todefaultAppPollInterval.