Skip to content

Commit 64642bb

Browse files
authored
Dump fork output on unclean exit (microsoft#24394)
* Dump fork output on unclean exit * Remember to clear timeout on process exit in case processes exit at very different times
1 parent 8f9c086 commit 64642bb

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/harness/parallel/host.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ namespace Harness.Parallel.Host {
1313
on(event: "message", listener: (message: ParallelClientMessage) => void): this;
1414
kill(signal?: string): void;
1515
currentTasks?: {file: string}[]; // Custom monkeypatch onto child process handle
16+
accumulatedOutput: string; // Custom monkeypatch with process output
17+
stderr: PartialStream;
18+
stdout: PartialStream;
19+
}
20+
21+
interface PartialStream {
22+
on(event: "data", listener: (chunk: Buffer) => void): this;
1623
}
1724

1825
interface ProgressBarsOptions {
@@ -151,7 +158,13 @@ namespace Harness.Parallel.Host {
151158
const config: TestConfig = { light: lightMode, listenForWork: true, runUnitTests, stackTraceLimit };
152159
const configPath = ts.combinePaths(taskConfigsFolder, `task-config${i}.json`);
153160
IO.writeFile(configPath, JSON.stringify(config));
154-
const child = fork(__filename, [`--config="${configPath}"`]);
161+
const child = fork(__filename, [`--config="${configPath}"`], { stdio: ["pipe", "pipe", "pipe", "ipc"] });
162+
child.accumulatedOutput = "";
163+
const appendOutput = (d: Buffer) => {
164+
child.accumulatedOutput += d.toString();
165+
};
166+
child.stderr.on("data", appendOutput);
167+
child.stdout.on("data", appendOutput);
155168
let currentTimeout = defaultTimeout;
156169
const killChild = () => {
157170
child.kill();
@@ -166,8 +179,10 @@ namespace Harness.Parallel.Host {
166179
return process.exit(2);
167180
});
168181
child.on("exit", (code, _signal) => {
182+
clearTimeout(timer);
169183
if (code !== 0) {
170-
console.error("Test worker process exited with nonzero exit code!");
184+
console.error(`Test worker process exited with nonzero exit code! Output:
185+
${child.accumulatedOutput}`);
171186
return process.exit(2);
172187
}
173188
});
@@ -223,6 +238,7 @@ namespace Harness.Parallel.Host {
223238
// No more tasks to distribute
224239
child.send({ type: "close" });
225240
closedWorkers++;
241+
clearTimeout(timer);
226242
if (closedWorkers === workerCount) {
227243
outputFinalResult();
228244
}

0 commit comments

Comments
 (0)