

























@@ -1418,6 +1418,103 @@ describe("kitchen-sink RPC process sampling", () => {
14181418]);
14191419});
142014201421+it("falls back to strict tasklist RSS when Windows PowerShell sampling fails", async () => {
1422+const calls: string[] = [];
1423+const sample = await sampleWindowsProcessByPort(19675, {
1424+runCommand: async (command: string) => {
1425+calls.push(command);
1426+if (command === "netstat.exe") {
1427+return {
1428+stdout: [
1429+" Proto Local Address Foreign Address State PID",
1430+" TCP 127.0.0.1:19675 0.0.0.0:0 LISTENING 6789",
1431+].join("\r\n"),
1432+stderr: "",
1433+};
1434+}
1435+if (command === "powershell.exe" || command === "powershell") {
1436+throw new Error("powershell unavailable");
1437+}
1438+if (command === "tasklist.exe") {
1439+return {
1440+stdout: '"node.exe","6789","Console","1","262,144 K"',
1441+stderr: "",
1442+};
1443+}
1444+throw new Error(`unexpected command ${command}`);
1445+},
1446+});
1447+1448+expect(sample).toEqual({
1449+cpuPercent: null,
1450+cpuSeconds: null,
1451+processId: 6789,
1452+rssMiB: 256,
1453+});
1454+expect(calls).toEqual(["netstat.exe", "powershell.exe", "powershell", "tasklist.exe"]);
1455+});
1456+1457+it("falls back to the known Windows pid when tasklist reports malformed pid text", async () => {
1458+const sample = await sampleWindowsProcessByPort(19675, {
1459+runCommand: async (command: string) => {
1460+if (command === "netstat.exe") {
1461+return {
1462+stdout: [
1463+" Proto Local Address Foreign Address State PID",
1464+" TCP 127.0.0.1:19675 0.0.0.0:0 LISTENING 6789",
1465+].join("\r\n"),
1466+stderr: "",
1467+};
1468+}
1469+if (command === "powershell.exe" || command === "powershell") {
1470+throw new Error("powershell unavailable");
1471+}
1472+if (command === "tasklist.exe") {
1473+return {
1474+stdout: '"node.exe","9999x","Console","1","262,144 K"',
1475+stderr: "",
1476+};
1477+}
1478+throw new Error(`unexpected command ${command}`);
1479+},
1480+});
1481+1482+expect(sample).toEqual({
1483+cpuPercent: null,
1484+cpuSeconds: null,
1485+processId: 6789,
1486+rssMiB: 256,
1487+});
1488+});
1489+1490+it("rejects malformed tasklist RSS instead of stripping digits", async () => {
1491+const sample = await sampleWindowsProcessByPort(19675, {
1492+runCommand: async (command: string) => {
1493+if (command === "netstat.exe") {
1494+return {
1495+stdout: [
1496+" Proto Local Address Foreign Address State PID",
1497+" TCP 127.0.0.1:19675 0.0.0.0:0 LISTENING 6789",
1498+].join("\r\n"),
1499+stderr: "",
1500+};
1501+}
1502+if (command === "powershell.exe" || command === "powershell") {
1503+throw new Error("powershell unavailable");
1504+}
1505+if (command === "tasklist.exe") {
1506+return {
1507+stdout: '"node.exe","6789","Console","1","262x144 K"',
1508+stderr: "",
1509+};
1510+}
1511+throw new Error(`unexpected command ${command}`);
1512+},
1513+});
1514+1515+expect(sample).toBeNull();
1516+});
1517+14211518it("samples direct POSIX gateway RSS with descendants", async () => {
14221519const sample = await sampleProcess(4321, {
14231520platform: "linux",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。