Skip to content

refactor: improve e2e test reporting #10304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🧹
  • Loading branch information
aslilac committed Oct 16, 2023
commit 91475e468fed24c49efed415fb4c4b59357f69ec
37 changes: 13 additions & 24 deletions site/e2e/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console -- Logging is sort of the whole point here */
import * as fs from "fs";
import * as fs from "fs/promises";
import type {
FullConfig,
Suite,
Expand Down Expand Up @@ -66,11 +66,15 @@ class CoderReporter implements Reporter {
this.timedOutTests.push(test);
}

const outputFile = `test-results/debug-pprof-goroutine-${test.title}.txt`;
await exportDebugPprof(outputFile);

const preserve = this.config?.preserveOutput;
const logOutput =
preserve === "always" ||
(result.status !== "passed" && preserve !== "never");
if (logOutput) {
console.log(`Data from pprof has been saved to ${outputFile}`);
console.log("==> Output");
const output = this.testOutput.get(test.id)!;
for (const [target, chunk] of output) {
Expand All @@ -92,8 +96,6 @@ class CoderReporter implements Reporter {
}
}
this.testOutput.delete(test.id);

await exportDebugPprof(test.title);
}

onEnd(result: FullResult) {
Expand All @@ -114,28 +116,15 @@ class CoderReporter implements Reporter {
}
}

const exportDebugPprof = async (testName: string) => {
const url = "http://127.0.0.1:6060/debug/pprof/goroutine?debug=1";
const outputFile = `test-results/debug-pprof-goroutine-${testName}.txt`;

await axios
.get(url)
.then((response) => {
if (response.status !== 200) {
throw new Error(`Error: Received status code ${response.status}`);
}
const exportDebugPprof = async (outputFile: string) => {
const response = await axios.get(
"http://127.0.0.1:6060/debug/pprof/goroutine?debug=1",
);
if (response.status !== 200) {
throw new Error(`Error: Received status code ${response.status}`);
}

fs.writeFile(outputFile, response.data, (err) => {
if (err) {
throw new Error(`Error writing to ${outputFile}: ${err.message}`);
} else {
console.log(`Data from ${url} has been saved to ${outputFile}`);
}
});
})
.catch((error) => {
throw new Error(`Error: ${error.message}`);
});
await fs.writeFile(outputFile, response.data);
};

const reportError = (error: TestError) => {
Expand Down