Skip to content
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

test: changed the way of reacting to the end of the test and adding timeout clearing #1076

Draft
wants to merge 8 commits into
base: beta
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 18 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@
"typedoc-plugin-markdown": "^3.17.1",
"typedoc-plugin-merge-modules": "^5.1.0",
"typedoc-theme-hierarchy": "4.1.2",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"@types/wtfnode": "^0.7.3",
"wtfnode": "^0.9.3"
},
"optionalDependencies": {
"@rollup/rollup-darwin-x64": "^4",
Expand Down
4 changes: 4 additions & 0 deletions src/golem-network/golem-network.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as wtf from "wtfnode";
import { anyAbortSignal, createAbortSignalFromTimeout, defaultLogger, isNode, Logger, YagnaApi } from "../shared/utils";
import {
Demand,
Expand Down Expand Up @@ -362,6 +363,9 @@ export class GolemNetwork {
* @return Resolves when all shutdown steps are completed
*/
async disconnect() {
setTimeout(() => {
wtf.dump();
}, 33_333);
if (this.disconnectPromise) {
return this.disconnectPromise;
}
Expand Down
35 changes: 29 additions & 6 deletions tests/examples/examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { spawn } from "child_process";
import { dirname, basename, resolve } from "path";
import chalk from "chalk";
import testExamples from "./examples.json";

const criticalLogsRegExp = [
/GolemInternalError/,
/GolemPlatformError/,
Expand All @@ -25,15 +24,43 @@ async function test(cmd: string, path: string, args: string[] = [], timeout = 36
const file = basename(path);
const cwd = dirname(path);
const env = { ...process.env, DEBUG: "golem-js:*" };
const spawnedExample = spawn(cmd, [file, ...args], { cwd, env });
const spawnedExample = spawn(cmd, [file, ...args], { cwd, env, stdio: ["ignore", "pipe", "pipe"] });
spawnedExample.stdout?.setEncoding("utf-8");
spawnedExample.stderr?.setEncoding("utf-8");
let error = "";
const timeoutId = setTimeout(() => {
error = `Test timeout was reached after ${timeout} seconds.`;
console.log({
error,
connected: spawnedExample.connected,
code: spawnedExample.exitCode,
signal: spawnedExample.signalCode,
pid: spawnedExample.pid,
eventNames: spawnedExample.eventNames(),
});
spawnedExample.kill();
}, timeout * 1000);
return new Promise((res, rej) => {
let isFinishing = false;
const finishTest = (code?: number, signal?: string) => {
if (isFinishing) {
console.log("Test finishing has already been triggered by another event");
return;
}
console.log(`Subprocess with test "${file}" exited with code ${code}, signal ${signal}`);
isFinishing = true;
spawnedExample.removeAllListeners();
spawnedExample.stdout.removeAllListeners();
spawnedExample.stderr.removeAllListeners();
clearTimeout(timeoutId);
if (!error && !code) return res(true);
rej(`Test example "${file}" failed. ${error}`);
};
spawnedExample.on("exit", finishTest);
spawnedExample.on("error", (err) => {
error = `The test ended with an error: ${err}`;
spawnedExample.kill();
});
const assertLogs = (data: string) => {
console.log(data.trim());
const logWithoutColors = data.replace(
Expand All @@ -47,10 +74,6 @@ async function test(cmd: string, path: string, args: string[] = [], timeout = 36
};
spawnedExample.stdout?.on("data", assertLogs);
spawnedExample.stderr?.on("data", assertLogs);
spawnedExample.on("close", (code) => {
if (!error && !code) return res(true);
rej(`Test example "${file}" failed. ${error}`);
});
}).finally(() => {
clearTimeout(timeoutId);
spawnedExample.kill("SIGKILL");
Expand Down
Loading