Skip to content

Commit 91475e4

Browse files
committed
🧹
1 parent 335593a commit 91475e4

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

site/e2e/reporter.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console -- Logging is sort of the whole point here */
2-
import * as fs from "fs";
2+
import * as fs from "fs/promises";
33
import type {
44
FullConfig,
55
Suite,
@@ -66,11 +66,15 @@ class CoderReporter implements Reporter {
6666
this.timedOutTests.push(test);
6767
}
6868

69+
const outputFile = `test-results/debug-pprof-goroutine-${test.title}.txt`;
70+
await exportDebugPprof(outputFile);
71+
6972
const preserve = this.config?.preserveOutput;
7073
const logOutput =
7174
preserve === "always" ||
7275
(result.status !== "passed" && preserve !== "never");
7376
if (logOutput) {
77+
console.log(`Data from pprof has been saved to ${outputFile}`);
7478
console.log("==> Output");
7579
const output = this.testOutput.get(test.id)!;
7680
for (const [target, chunk] of output) {
@@ -92,8 +96,6 @@ class CoderReporter implements Reporter {
9296
}
9397
}
9498
this.testOutput.delete(test.id);
95-
96-
await exportDebugPprof(test.title);
9799
}
98100

99101
onEnd(result: FullResult) {
@@ -114,28 +116,15 @@ class CoderReporter implements Reporter {
114116
}
115117
}
116118

117-
const exportDebugPprof = async (testName: string) => {
118-
const url = "http://127.0.0.1:6060/debug/pprof/goroutine?debug=1";
119-
const outputFile = `test-results/debug-pprof-goroutine-${testName}.txt`;
120-
121-
await axios
122-
.get(url)
123-
.then((response) => {
124-
if (response.status !== 200) {
125-
throw new Error(`Error: Received status code ${response.status}`);
126-
}
119+
const exportDebugPprof = async (outputFile: string) => {
120+
const response = await axios.get(
121+
"http://127.0.0.1:6060/debug/pprof/goroutine?debug=1",
122+
);
123+
if (response.status !== 200) {
124+
throw new Error(`Error: Received status code ${response.status}`);
125+
}
127126

128-
fs.writeFile(outputFile, response.data, (err) => {
129-
if (err) {
130-
throw new Error(`Error writing to ${outputFile}: ${err.message}`);
131-
} else {
132-
console.log(`Data from ${url} has been saved to ${outputFile}`);
133-
}
134-
});
135-
})
136-
.catch((error) => {
137-
throw new Error(`Error: ${error.message}`);
138-
});
127+
await fs.writeFile(outputFile, response.data);
139128
};
140129

141130
const reportError = (error: TestError) => {

0 commit comments

Comments
 (0)