Performance: fetch all docker container statuses in one request (#7092)

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
DaddyBoard
2026-09-05 15:17:52 +00:00
committed by GitHub
co-authored by shamoon
parent df34927198
commit 438788240b
11 changed files with 617 additions and 365 deletions
+20 -8
View File
@@ -21,8 +21,11 @@ describe("components/services/status", () => {
render(<Status service={{ container: "c", server: "s" }} />);
expect(useSWR).toHaveBeenCalledWith("/api/docker/status/c/s");
expect(useSWR).toHaveBeenCalledWith("/api/docker/statuses?server=s");
expect(screen.getByText("docker.unknown")).toBeInTheDocument();
render(<Status service={{ container: "c" }} />);
expect(useSWR).toHaveBeenCalledWith("/api/docker/statuses?server=");
});
it("renders error when SWR fails", () => {
@@ -33,30 +36,39 @@ describe("components/services/status", () => {
expect(screen.getByText("docker.error")).toBeInTheDocument();
});
it("renders error when the api returns an error payload with a 200-parsed body", () => {
useSWR.mockReturnValue({ data: { error: "query failed" }, error: undefined });
render(<Status service={{ container: "c", server: "s" }} />);
expect(screen.getByText("docker.error")).toBeInTheDocument();
expect(screen.queryByText("docker.not_found")).not.toBeInTheDocument();
});
it("renders healthy/unhealthy and partial/exited/not found statuses", () => {
useSWR.mockReturnValue({ data: { status: "running", health: "healthy" }, error: undefined });
useSWR.mockReturnValue({ data: { statuses: { c: { status: "running", health: "healthy" } } }, error: undefined });
render(<Status service={{ container: "c", server: "s" }} />);
expect(screen.getByText("docker.healthy")).toBeInTheDocument();
useSWR.mockReturnValue({ data: { status: "running", health: "unhealthy" }, error: undefined });
useSWR.mockReturnValue({ data: { statuses: { c: { status: "running", health: "unhealthy" } } }, error: undefined });
render(<Status service={{ container: "c", server: "s" }} />);
expect(screen.getByText("docker.unhealthy")).toBeInTheDocument();
useSWR.mockReturnValue({ data: { status: "partial 1/2" }, error: undefined });
useSWR.mockReturnValue({ data: { statuses: { c: { status: "partial 1/2" } } }, error: undefined });
render(<Status service={{ container: "c", server: "s" }} />);
expect(screen.getByText("docker.partial 1/2")).toBeInTheDocument();
useSWR.mockReturnValue({ data: { status: "exited" }, error: undefined });
useSWR.mockReturnValue({ data: { statuses: { c: { status: "exited" } } }, error: undefined });
render(<Status service={{ container: "c", server: "s" }} />);
expect(screen.getByText("docker.exited")).toBeInTheDocument();
useSWR.mockReturnValue({ data: { status: "not found" }, error: undefined });
useSWR.mockReturnValue({ data: { statuses: {} }, error: undefined });
render(<Status service={{ container: "c", server: "s" }} />);
expect(screen.getByText("docker.not_found")).toBeInTheDocument();
});
it("renders starting health when container is running and starting", () => {
useSWR.mockReturnValue({ data: { status: "running", health: "starting" }, error: undefined });
useSWR.mockReturnValue({ data: { statuses: { c: { status: "running", health: "starting" } } }, error: undefined });
render(<Status service={{ container: "c", server: "s" }} />);
@@ -64,7 +76,7 @@ describe("components/services/status", () => {
});
it("renders a dot when style is dot", () => {
useSWR.mockReturnValue({ data: { status: "running" }, error: undefined });
useSWR.mockReturnValue({ data: { statuses: { c: { status: "running" } } }, error: undefined });
const { container } = render(<Status service={{ container: "c", server: "s" }} style="dot" />);