Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ResourceTelemetryDiagnostics.logic.test.ts

48 lines1.3 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import type { ResourceTelemetryProcess } from "@t3tools/contracts";
4import * as DateTime from "effect/DateTime";
5​
6import { visibleResourceTelemetryProcesses } from "./ResourceTelemetryDiagnostics.logic";
7​
8const process = (pid: number, ppid: number, depth: number): ResourceTelemetryProcess => ({
9 identity: { pid, startTimeMs: pid * 1_000 },
10 ppid,
11 childPids: [],
12 depth,
13 name: `process-${pid}`,
14 command: `process-${pid}`,
15 status: "Running",
16 category: pid === 1 ? "server" : "server-child",
17 cpuPercent: 0,
18 cpuTimeMs: 0,
19 residentBytes: 0,
20 peakResidentBytes: 0,
21 virtualBytes: 0,
22 ioReadBytes: 0,
23 ioWriteBytes: 0,
24 ioReadBytesPerSecond: 0,
25 ioWriteBytesPerSecond: 0,
26 ioSemantics: "storage",
27 runTimeMs: 0,
28 firstSeenAt: DateTime.makeUnsafe(0),
29 lastSeenAt: DateTime.makeUnsafe(0),
30});
31​
32describe("visibleResourceTelemetryProcesses", () => {
33 it("hides descendants by parentage even when rows are not depth-first", () => {
34 const processes = [
35 process(1, 0, 0),
36 process(10, 0, 0),
37 process(2, 1, 1),
38 process(11, 10, 1),
39 process(3, 2, 2),
40 ];
41​
42 expect(visibleResourceTelemetryProcesses(processes, new Set(["1:1000"]))).toEqual([
43 processes[0],
44 processes[1],
45 processes[3],
46 ]);
47 });
48});