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 d850b47 commit 3c7f7bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 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("./worker22222.mjs", "/golem/input/worker.mjs")
.uploadFile("./worker.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
14 changes: 9 additions & 5 deletions tests/examples/examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ async function test(cmd: string, path: string, args: string[] = [], timeout = 18
let error = "";
const timeoutId = setTimeout(() => {
error = `Test timeout was reached after ${timeout} seconds.`;
spawnedExample.kill("SIGTERM");
spawnedExample.kill("SIGKILL");
spawnedExample.kill();
// for some reason the process doesn't exit after kill, it does so after I type enter
spawnedExample.stdin.write("\n");
spawnedExample.stdin.end();
}, timeout * 1000);
return new Promise((res, rej) => {
spawnedExample.stdout?.on("data", (data: string) => {
console.log(data.trim());
if (criticalLogsRegExp.some((regexp) => data.match(regexp))) {
error = `A critical error occurred during the test.`;
spawnedExample.kill("SIGTERM");
spawnedExample.kill("SIGKILL");
spawnedExample.kill();
spawnedExample.stdin.write("\n");
spawnedExample.stdin.end();
}
});
spawnedExample.on("close", (code) => {
Expand Down Expand Up @@ -66,8 +69,9 @@ async function testAll(examples: Example[]) {
try {
console.log(chalk.yellow(`\n---- Starting test: "${example.path}" ----\n`));
await test(example.cmd, example.path, example.args, example.timeout);
console.log(chalk.bgGreen.white(" PASS "), chalk.green(example.path));
} catch (error) {
console.error(chalk.bgRed.white(" FAIL "), chalk.red(error));
console.log(chalk.bgRed.white(" FAIL "), chalk.red(error));
failedTests.add(example.path);
}
}
Expand Down

0 comments on commit 3c7f7bf

Please sign in to comment.