Skip to content

Commit

Permalink
test(examples): fixed examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mgordel committed Sep 20, 2023
1 parent bf1cf03 commit 51a22d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TaskExecutor } from "@golem-sdk/golem-js";
const result = await executor.run(async (ctx) => {
const res = await ctx
.beginBatch()
.uploadFile("./worker.mjs", "/golem/input/worker.mjs")
.uploadFile("./worker22222.mjs", "/golem/input/worker.mjs")
.run("node /golem/input/worker.mjs > /golem/input/output.txt")
.run("cat /golem/input/output.txt")
.downloadFile("/golem/input/output.txt", "./output.txt")
Expand Down
10 changes: 4 additions & 6 deletions tests/examples/examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@ async function test(cmd: string, path: string, args: string[] = [], timeout = 18
const cwd = dirname(path);
const spawnedExample = spawn(cmd, [file, ...args], { cwd });
spawnedExample.stdout?.setEncoding("utf-8");
const timeoutId = setTimeout(() => {
spawnedExample.kill("SIGABRT");
}, timeout * 1000);
const timeoutId = setTimeout(() => spawnedExample.kill("SIGINT"), timeout * 1000);
return new Promise((res, rej) => {
spawnedExample.stdout?.on("data", (data: string) => {
console.log(data.trim());
if (criticalLogsRegExp.some((regexp) => data.match(regexp))) {
spawnedExample.kill("SIGKILL");
spawnedExample.kill("SIGTERM");
}
});
spawnedExample.on("close", (code, signal) => {
if (signal === null) return res(true);
let errorMsg = "";
if (signal === "SIGABRT") errorMsg = `Test timeout was reached after ${timeout} seconds.`;
if (signal === "SIGKILL") errorMsg = `A critical error occurred during the test.`;
if (signal === "SIGINT") errorMsg = `Test timeout was reached after ${timeout} seconds.`;
if (signal === "SIGTERM") errorMsg = `A critical error occurred during the test.`;
rej(`Test example "${file}" failed. ${errorMsg}`);
});
}).finally(() => {
Expand Down

0 comments on commit 51a22d4

Please sign in to comment.