Skip to content

fix: display explicit 'retry' button(s) when a workspace fails #10720

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

Merged
merged 16 commits into from
Nov 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip: add tests for workspace retries (breaks 2 previous tests
  • Loading branch information
Parkreiner committed Nov 16, 2023
commit 2c55fd80f63030677550f41b6bd56c0b28aaafb5
90 changes: 89 additions & 1 deletion site/src/pages/WorkspacePage/WorkspacePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { rest } from "msw";
import {
MockTemplate,
MockWorkspace,
MockFailedWorkspace,
MockWorkspaceBuild,
MockStoppedWorkspace,
MockStartingWorkspace,
Expand All @@ -22,7 +23,7 @@ import { renderWithAuth } from "testHelpers/renderHelpers";
import { server } from "testHelpers/server";
import { WorkspacePage } from "./WorkspacePage";

// It renders the workspace page and waits for it be loaded
// Renders the workspace page and waits for it be loaded
const renderWorkspacePage = async (workspace: Workspace) => {
jest.spyOn(api, "getWorkspaceByOwnerAndName").mockResolvedValue(workspace);
jest.spyOn(api, "getTemplate").mockResolvedValueOnce(MockTemplate);
Expand Down Expand Up @@ -369,4 +370,91 @@ describe("WorkspacePage", () => {
});
});
});

// Tried to get these wired up via describe.each to reduce repetition, but the
// syntax just got too convoluted because of the variance in what arguments
// each function gets called with
describe("Retrying failed workspaces", () => {
const retryButtonRe = /^Retry$/i;
const retryDebugButtonRe = /^Retry \(Debug\)$/i;

describe("Retries a failed 'Start' transition", () => {
const mockStart = jest.spyOn(api, "startWorkspace");
const failedStart: Workspace = {
...MockFailedWorkspace,
latest_build: {
...MockFailedWorkspace.latest_build,
transition: "start",
},
};

test("Retry with no debug", async () => {
await testButton(failedStart, retryButtonRe, mockStart);

expect(mockStart).toBeCalledWith(
failedStart.id,
failedStart.latest_build.template_version_id,
undefined,
undefined,
);
});

test("Retry with debug logs", async () => {
await testButton(failedStart, retryDebugButtonRe, mockStart);

expect(mockStart).toBeCalledWith(
failedStart.id,
failedStart.latest_build.template_version_id,
"debug",
undefined,
);
});
});

describe("Retries a failed 'Stop' transition", () => {
const mockStop = jest.spyOn(api, "stopWorkspace");
const failedStop: Workspace = {
...MockFailedWorkspace,
latest_build: {
...MockFailedWorkspace.latest_build,
transition: "stop",
},
};

test("Retry with no debug", async () => {
await testButton(failedStop, retryButtonRe, mockStop);
expect(mockStop).toBeCalledWith(failedStop.id, undefined);
});

test("Retry with debug logs", async () => {
await testButton(failedStop, retryDebugButtonRe, mockStop);
expect(mockStop).toBeCalledWith(failedStop.id, "debug");
});
});

describe("Retries a failed 'Delete' transition", () => {
const mockDelete = jest.spyOn(api, "deleteWorkspace");
const failedDelete: Workspace = {
...MockFailedWorkspace,
latest_build: {
...MockFailedWorkspace.latest_build,
transition: "delete",
},
};

test("Retry with no debug", async () => {
await testButton(failedDelete, retryButtonRe, mockDelete);
expect(mockDelete).toBeCalledWith(failedDelete.id, {
logLevel: undefined,
});
});

test("Retry with debug logs", async () => {
await testButton(failedDelete, retryDebugButtonRe, mockDelete);
expect(mockDelete).toBeCalledWith(failedDelete.id, {
logLevel: "debug",
});
});
});
});
});