GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test(telemetry): derive fixture PIDs from the test worker PID · pingdotgg/t3code@a183588

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • diagnostics
      • ProcessDiagnostics.test.ts
    • resourceTelemetry
      • ResourceTelemetry.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/diagnostics/ProcessDiagnostics.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/diagnostics/ProcessDiagnostics.test.ts
+25-18Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import * as ResourceAttribution from "../resourceTelemetry/ResourceAttribution.t
1515
import * as ResourceTelemetry from "../resourceTelemetry/ResourceTelemetry.ts";
1616
import * as ProcessDiagnostics from "./ProcessDiagnostics.ts";
1717

18+
// ProcessDiagnostics treats process.pid as the server, so the fixture PID is an
19+
// offset from it. A fixed PID collides whenever the test worker is assigned it.
20+
const SERVER_PID = process.pid;
21+
const CHILD_PID = SERVER_PID + 1;
22+
1823
function makeNativeSnapshot(
1924
processes: ResourceMonitorSnapshotEvent["processes"],
2025
): ResourceMonitorSnapshotEvent {
@@ -66,7 +71,7 @@ describe("ProcessDiagnostics", () => {
6671
Effect.gen(function* () {
6772
const snapshot = makeNativeSnapshot([
6873
{
69-
pid: process.pid,
74+
pid: SERVER_PID,
7075
ppid: 1,
7176
startTimeMs: 1_000,
7277
runTimeMs: 60_000,
@@ -82,8 +87,8 @@ describe("ProcessDiagnostics", () => {
8287
ioSemantics: "storage",
8388
},
8489
{
85-
pid: 4_242,
86-
ppid: process.pid,
90+
pid: CHILD_PID,
91+
ppid: SERVER_PID,
8792
startTimeMs: 2_000,
8893
runTimeMs: 4_000,
8994
name: "agent",
@@ -106,7 +111,7 @@ describe("ProcessDiagnostics", () => {
106111
return yield* processDiagnostics.read;
107112
}).pipe(Effect.provide(layer));
108113

109-
expect(diagnostics.processes.map((process) => process.pid)).toEqual([4242]);
114+
expect(diagnostics.processes.map((process) => process.pid)).toEqual([CHILD_PID]);
110115
expect(diagnostics.processes[0]?.startTimeMs).toBe(2_000);
111116
expect(diagnostics.processes[0]?.cpuPercent).toBe(1.5);
112117
expect(diagnostics.processes[0]?.rssBytes).toBe(2_048);
@@ -122,7 +127,7 @@ describe("ProcessDiagnostics", () => {
122127
const result = yield* Effect.service(ProcessDiagnostics.ProcessDiagnostics).pipe(
123128
Effect.flatMap((processDiagnostics) =>
124129
processDiagnostics.signal({
125-
pid: 4_242,
130+
pid: CHILD_PID,
126131
startTimeMs: 2_000,
127132
signal: "SIGINT",
128133
}),
@@ -131,10 +136,12 @@ describe("ProcessDiagnostics", () => {
131136
);
132137

133138
expect(result).toEqual({
134-
pid: 4242,
139+
pid: CHILD_PID,
135140
signal: "SIGINT",
136141
signaled: false,
137-
message: Option.some("Process 4242 no longer matches the selected process identity."),
142+
message: Option.some(
143+
`Process ${CHILD_PID} no longer matches the selected process identity.`,
144+
),
138145
});
139146
}),
140147
);
@@ -143,8 +150,8 @@ describe("ProcessDiagnostics", () => {
143150
Effect.gen(function* () {
144151
const snapshot = makeNativeSnapshot([
145152
{
146-
pid: 4_242,
147-
ppid: process.pid,
153+
pid: CHILD_PID,
154+
ppid: SERVER_PID,
148155
startTimeMs: 2_000,
149156
runTimeMs: 4_000,
150157
name: "agent",
@@ -185,7 +192,7 @@ describe("ProcessDiagnostics", () => {
185192
const result = yield* Effect.service(ProcessDiagnostics.ProcessDiagnostics).pipe(
186193
Effect.flatMap((processDiagnostics) =>
187194
processDiagnostics.signal({
188-
pid: 4_242,
195+
pid: CHILD_PID,
189196
startTimeMs: 2_000,
190197
signal: "SIGINT",
191198
}),
@@ -194,11 +201,11 @@ describe("ProcessDiagnostics", () => {
194201
);
195202

196203
expect(result).toEqual({
197-
pid: 4_242,
204+
pid: CHILD_PID,
198205
signal: "SIGINT",
199206
signaled: false,
200207
message: Option.some(
201-
"Could not refresh process 4242; refusing to signal a stale identity.",
208+
`Could not refresh process ${CHILD_PID}; refusing to signal a stale identity.`,
202209
),
203210
});
204211
}),
@@ -211,7 +218,7 @@ describe("ProcessDiagnostics", () => {
211218
);
212219
const snapshot = makeNativeSnapshot([
213220
{
214-
pid: 4_242,
221+
pid: CHILD_PID,
215222
ppid: 1,
216223
startTimeMs: 2_000,
217224
runTimeMs: 4_000,
@@ -233,7 +240,7 @@ describe("ProcessDiagnostics", () => {
233240
type: "desktopTelemetry",
234241
sequence: 1,
235242
sampledAtUnixMs,
236-
electronPid: 4_242,
243+
electronPid: CHILD_PID,
237244
power: {
238245
source: "electron-main",
239246
idle: "false",
@@ -249,7 +256,7 @@ describe("ProcessDiagnostics", () => {
249256
speedLimitPercent: Option.none(),
250257
electronProcesses: [
251258
{
252-
pid: 4_242,
259+
pid: CHILD_PID,
253260
creationTimeMs: 2_000,
254261
type: "Browser",
255262
name: "electron",
@@ -265,7 +272,7 @@ describe("ProcessDiagnostics", () => {
265272
const result = yield* Effect.service(ProcessDiagnostics.ProcessDiagnostics).pipe(
266273
Effect.flatMap((processDiagnostics) =>
267274
processDiagnostics.signal({
268-
pid: 4_242,
275+
pid: CHILD_PID,
269276
startTimeMs: 2_000,
270277
signal: "SIGKILL",
271278
}),
@@ -274,10 +281,10 @@ describe("ProcessDiagnostics", () => {
274281
);
275282

276283
expect(result).toEqual({
277-
pid: 4_242,
284+
pid: CHILD_PID,
278285
signal: "SIGKILL",
279286
signaled: false,
280-
message: Option.some("Process 4242 is not a signalable T3 backend descendant."),
287+
message: Option.some(`Process ${CHILD_PID} is not a signalable T3 backend descendant.`),
281288
});
282289

283290
const diagnostics = yield* Effect.service(ProcessDiagnostics.ProcessDiagnostics).pipe(
Collapse file

‎apps/server/src/resourceTelemetry/ResourceTelemetry.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/resourceTelemetry/ResourceTelemetry.test.ts
+42-29Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ import * as NativeTelemetryClient from "./NativeTelemetryClient.ts";
2121
import * as ResourceAttribution from "./ResourceAttribution.ts";
2222
import * as ResourceTelemetry from "./ResourceTelemetry.ts";
2323

24+
// ResourceTelemetry classifies process.pid as the server, so fixture PIDs are
25+
// offsets from it. Fixed PIDs collide whenever the test worker is assigned one.
26+
const SERVER_PID = process.pid;
27+
const CODEX_PID = SERVER_PID + 1;
28+
const SHORT_LIVED_CHILD_PID = SERVER_PID + 2;
29+
const ELECTRON_PID = SERVER_PID + 3;
30+
const MONITOR_PID = SERVER_PID + 4;
31+
const RESTARTED_MONITOR_PID = SERVER_PID + 5;
32+
2433
function processSample(
2534
input: Partial<ResourceMonitorProcessSample> &
2635
Pick<ResourceMonitorProcessSample, "pid" | "ppid" | "startTimeMs">,
@@ -50,31 +59,31 @@ function nativeSnapshot(input: {
5059
}): ResourceMonitorSnapshotEvent {
5160
const processes = [
5261
processSample({
53-
pid: process.pid,
62+
pid: SERVER_PID,
5463
ppid: 1,
5564
startTimeMs: 100,
5665
cpuTimeMs: input.sequence * 10,
5766
}),
5867
processSample({
59-
pid: 4_242,
60-
ppid: process.pid,
68+
pid: CODEX_PID,
69+
ppid: SERVER_PID,
6170
startTimeMs: 200,
6271
name: "codex",
6372
command: "codex app-server",
6473
cpuTimeMs: input.childCpuTimeMs,
6574
ioWriteBytes: input.childWriteBytes,
6675
}),
6776
processSample({
68-
pid: 5_000,
77+
pid: ELECTRON_PID,
6978
ppid: 1,
7079
startTimeMs: 300,
7180
name: "electron",
7281
command: "electron",
7382
cpuTimeMs: input.sequence * 20,
7483
}),
7584
processSample({
76-
pid: 9_000,
77-
ppid: process.pid,
85+
pid: MONITOR_PID,
86+
ppid: SERVER_PID,
7887
startTimeMs: 400,
7988
name: "t3-resource-monitor",
8089
command: "t3-resource-monitor",
@@ -111,7 +120,7 @@ function desktopSnapshot(sampledAtUnixMs: number): DesktopHostTelemetrySnapshot
111120
type: "desktopTelemetry",
112121
sequence: 1,
113122
sampledAtUnixMs,
114-
electronPid: 5_000,
123+
electronPid: ELECTRON_PID,
115124
power: {
116125
source: "electron-main",
117126
idle: "false",
@@ -127,7 +136,7 @@ function desktopSnapshot(sampledAtUnixMs: number): DesktopHostTelemetrySnapshot
127136
speedLimitPercent: Option.some(90),
128137
electronProcesses: [
129138
{
130-
pid: 5_000,
139+
pid: ELECTRON_PID,
131140
creationTimeMs: 300,
132141
type: "Browser",
133142
name: "electron",
@@ -154,17 +163,17 @@ describe("ResourceTelemetry", () => {
154163
childWriteBytes: index * 100,
155164
});
156165
const processes = sample.processes
157-
.filter((entry) => entry.pid === process.pid || entry.pid === 4_242)
166+
.filter((entry) => entry.pid === SERVER_PID || entry.pid === CODEX_PID)
158167
.map((entry) =>
159-
entry.pid === 4_242
168+
entry.pid === CODEX_PID
160169
? { ...entry, startTimeMs: index }
161170
: { ...entry, ioWriteBytes: index * 100 },
162171
);
163172
if (index === 0 || index === 2) {
164173
processes.push(
165174
processSample({
166-
pid: 4_243,
167-
ppid: process.pid,
175+
pid: SHORT_LIVED_CHILD_PID,
176+
ppid: SERVER_PID,
168177
startTimeMs: 500,
169178
cpuTimeMs: index === 0 ? 100 : 350,
170179
ioWriteBytes: index === 0 ? 1_000 : 5_000,
@@ -192,18 +201,20 @@ describe("ResourceTelemetry", () => {
192201

193202
expect(history.topProcesses).toHaveLength(sampleCount + 2);
194203
expect(
195-
history.topProcesses.find((entry) => entry.identity.pid === process.pid),
204+
history.topProcesses.find((entry) => entry.identity.pid === SERVER_PID),
196205
).toMatchObject({
197206
sampleCount,
198207
cpuTimeMs: (sampleCount - 1) * 10,
199208
ioWriteBytes: (sampleCount - 1) * 100,
200209
});
201-
const children = history.topProcesses.filter((entry) => entry.identity.pid === 4_242);
210+
const children = history.topProcesses.filter((entry) => entry.identity.pid === CODEX_PID);
202211
expect(children).toHaveLength(sampleCount);
203212
for (const child of children) {
204213
expect(child).toMatchObject({ sampleCount: 1, cpuTimeMs: 0, ioWriteBytes: 0 });
205214
}
206-
expect(history.topProcesses.find((entry) => entry.identity.pid === 4_243)).toMatchObject({
215+
expect(
216+
history.topProcesses.find((entry) => entry.identity.pid === SHORT_LIVED_CHILD_PID),
217+
).toMatchObject({
207218
sampleCount: 2,
208219
cpuTimeMs: 250,
209220
ioWriteBytes: 4_000,
@@ -307,7 +318,7 @@ describe("ResourceTelemetry", () => {
307318
sampledAtUnixMs,
308319
childCpuTimeMs: 100,
309320
childWriteBytes: 1_000,
310-
externalProcesses: [{ pid: 5_000, startTimeMs: 300 }],
321+
externalProcesses: [{ pid: ELECTRON_PID, startTimeMs: 300 }],
311322
});
312323
const desktop = {
313324
...desktopSnapshot(sampledAtUnixMs),
@@ -336,9 +347,9 @@ describe("ResourceTelemetry", () => {
336347
return yield* telemetry.refresh;
337348
}).pipe(Effect.provide(layerTelemetry));
338349

339-
expect(snapshot.processes.find((entry) => entry.identity.pid === 5_000)?.category).toBe(
340-
"electron-main",
341-
);
350+
expect(
351+
snapshot.processes.find((entry) => entry.identity.pid === ELECTRON_PID)?.category,
352+
).toBe("electron-main");
342353
expect(snapshot.groups.electron.processStarts).toBe(1);
343354
expect(snapshot.groups.backend.processStarts).toBe(3);
344355
}),
@@ -574,7 +585,7 @@ describe("ResourceTelemetry", () => {
574585
version: 3,
575586
type: "hello",
576587
sidecarVersion: "0.1.0",
577-
sidecarPid: 9_000,
588+
sidecarPid: MONITOR_PID,
578589
platform: "test",
579590
arch: "test",
580591
capabilities: {
@@ -629,7 +640,9 @@ describe("ResourceTelemetry", () => {
629640
const telemetry = yield* ResourceTelemetry.ResourceTelemetry;
630641
const attribution = yield* ResourceAttribution.ResourceAttribution;
631642

632-
expect(yield* Ref.get(externalProcesses)).toEqual([{ pid: 5_000, startTimeMs: 300 }]);
643+
expect(yield* Ref.get(externalProcesses)).toEqual([
644+
{ pid: ELECTRON_PID, startTimeMs: 300 },
645+
]);
633646

634647
yield* attribution.record({
635648
component: "provider-event-log",
@@ -657,7 +670,7 @@ describe("ResourceTelemetry", () => {
657670

658671
yield* TestClock.adjust(Duration.seconds(1));
659672
const second = yield* telemetry.refresh;
660-
const codex = second.processes.find((entry) => entry.identity.pid === 4_242);
673+
const codex = second.processes.find((entry) => entry.identity.pid === CODEX_PID);
661674
expect(codex?.cpuPercent).toBe(25);
662675
expect(codex?.ioWriteBytesPerSecond).toBe(4_000);
663676
expect(second.groups.backend.ioWriteBytes).toBe(4_000);
@@ -671,13 +684,13 @@ describe("ResourceTelemetry", () => {
671684
});
672685
expect(history.retainedSampleCount).toBeGreaterThan(0);
673686
expect(
674-
history.topProcesses.find((entry) => entry.identity.pid === 4_242)?.sampleCount,
687+
history.topProcesses.find((entry) => entry.identity.pid === CODEX_PID)?.sampleCount,
675688
).toBe(2);
676-
expect(history.topProcesses.find((entry) => entry.identity.pid === 4_242)?.cpuTimeMs).toBe(
677-
250,
678-
);
679689
expect(
680-
history.topProcesses.find((entry) => entry.identity.pid === 4_242)?.ioWriteBytes,
690+
history.topProcesses.find((entry) => entry.identity.pid === CODEX_PID)?.cpuTimeMs,
691+
).toBe(250);
692+
expect(
693+
history.topProcesses.find((entry) => entry.identity.pid === CODEX_PID)?.ioWriteBytes,
681694
).toBe(4_000);
682695
expect(history.buckets.reduce((total, bucket) => total + bucket.ioWriteBytes, 0)).toBe(
683696
4_000,
@@ -691,14 +704,14 @@ describe("ResourceTelemetry", () => {
691704
...current,
692705
hello: Option.map(current.hello, (hello) => ({
693706
...hello,
694-
sidecarPid: 9_001,
707+
sidecarPid: RESTARTED_MONITOR_PID,
695708
})),
696709
restartCount: 3,
697710
}));
698711
yield* TestClock.adjust(Duration.seconds(1));
699712
const restarted = yield* telemetry.refresh;
700713
expect(DateTime.toEpochMillis(restarted.readAt)).toBe(startedAt + 2_000);
701-
expect(Option.getOrNull(restarted.health.sidecarPid)).toBe(9_001);
714+
expect(Option.getOrNull(restarted.health.sidecarPid)).toBe(RESTARTED_MONITOR_PID);
702715

703716
yield* Ref.update(nativeHealth, (current) => ({
704717
...current,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.