

















@@ -1,4 +1,4 @@
1-import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
1+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
22import path from "node:path";
33import { afterEach, describe, expect, it } from "vitest";
44import { testing } from "../../scripts/check-gateway-cpu-scenarios.mjs";
@@ -52,11 +52,7 @@ describe("gateway CPU scenario guard", () => {
5252it("does not run the startup bench when the startup build fails", async () => {
5353const outputDir = makeTempRoot();
5454const calls: string[][] = [];
55-const options = testing.parseArgs([
56-"--output-dir",
57-outputDir,
58-"--skip-qa",
59-]);
55+const options = testing.parseArgs(["--output-dir", outputDir, "--skip-qa"]);
60566157const result = await testing.runGatewayCpuScenarios(options, {
6258silent: true,
@@ -73,4 +69,51 @@ describe("gateway CPU scenario guard", () => {
7369{ name: "startup bench", signal: null, status: 1 },
7470]);
7571});
72+73+it("fails when completed runs report hot gateway CPU observations", async () => {
74+const outputDir = makeTempRoot();
75+const startupOutput = path.join(outputDir, "gateway-startup-bench.json");
76+const options = testing.parseArgs([
77+"--output-dir",
78+outputDir,
79+"--skip-qa",
80+"--cpu-core-warn",
81+"0.9",
82+"--hot-wall-warn-ms",
83+"30000",
84+]);
85+86+const result = await testing.runGatewayCpuScenarios(options, {
87+silent: true,
88+spawnSync: (_command: string, args: string[]) => {
89+if (args.includes("scripts/bench-gateway-startup.ts")) {
90+writeFileSync(
91+startupOutput,
92+`${JSON.stringify({
93+ results: [
94+ {
95+ id: "default",
96+ summary: {
97+ cpuCoreRatio: { max: 1.15 },
98+ readyzMs: { max: 45_000 },
99+ },
100+ },
101+ ],
102+ })}\n`,
103+);
104+}
105+return { status: 0 };
106+},
107+});
108+109+expect(result.exitCode).toBe(1);
110+expect(result.summary.observations).toEqual([
111+{
112+kind: "startup-cpu-hot",
113+id: "default",
114+cpuCoreRatioMax: 1.15,
115+wallMsMax: 45_000,
116+},
117+]);
118+});
76119});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。