
























@@ -0,0 +1,88 @@
1+import { afterEach, describe, expect, it, vi } from "vitest";
2+import { runTimedUpdateJob } from "../../scripts/e2e/parallels/update-job-timeout.ts";
3+4+describe("Parallels update job timeout", () => {
5+afterEach(() => {
6+vi.useRealTimers();
7+});
8+9+it("passes after the update body completes", async () => {
10+const chunks: string[] = [];
11+const writeLog = vi.fn(async () => undefined);
12+13+await expect(
14+runTimedUpdateJob({
15+append: (chunk) => chunks.push(chunk),
16+label: "macOS",
17+run: async () => undefined,
18+timeoutDescription: "1s",
19+timeoutMs: 1000,
20+ writeLog,
21+}),
22+).resolves.toBe(0);
23+24+expect(chunks).toEqual([]);
25+expect(writeLog).toHaveBeenCalledTimes(1);
26+});
27+28+it("records update failures and writes the job log", async () => {
29+const chunks: string[] = [];
30+const writeLog = vi.fn(async () => undefined);
31+32+await expect(
33+runTimedUpdateJob({
34+append: (chunk) => chunks.push(chunk),
35+label: "Linux",
36+run: async () => {
37+throw new Error("package swap failed");
38+},
39+timeoutDescription: "1s",
40+timeoutMs: 1000,
41+ writeLog,
42+}),
43+).resolves.toBe(1);
44+45+expect(chunks).toEqual(["package swap failed\n"]);
46+expect(writeLog).toHaveBeenCalledTimes(1);
47+});
48+49+it("lets the inner bounded operation settle before the backstop fires", async () => {
50+vi.useFakeTimers();
51+const chunks: string[] = [];
52+const writeLog = vi.fn(async () => undefined);
53+54+const result = runTimedUpdateJob({
55+append: (chunk) => chunks.push(chunk),
56+label: "macOS",
57+run: () => new Promise<void>((resolve) => setTimeout(resolve, 1000)),
58+timeoutDescription: "1s plus cleanup backstop",
59+timeoutMs: 1200,
60+ writeLog,
61+});
62+63+await vi.advanceTimersByTimeAsync(1000);
64+await expect(result).resolves.toBe(0);
65+expect(chunks).toEqual([]);
66+expect(writeLog).toHaveBeenCalledTimes(1);
67+});
68+69+it("fails and writes the job log when the update body hangs", async () => {
70+vi.useFakeTimers();
71+const chunks: string[] = [];
72+const writeLog = vi.fn(async () => undefined);
73+74+const result = runTimedUpdateJob({
75+append: (chunk) => chunks.push(chunk),
76+label: "Windows",
77+run: () => new Promise(() => undefined),
78+timeoutDescription: "1s",
79+timeoutMs: 1000,
80+ writeLog,
81+});
82+83+await vi.advanceTimersByTimeAsync(1000);
84+await expect(result).resolves.toBe(1);
85+expect(chunks).toEqual(["Windows update timed out after 1s\n"]);
86+expect(writeLog).toHaveBeenCalledTimes(1);
87+});
88+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。