From 3c7f7bffe10c08b57a24919a74d5e4a2c1d02fce Mon Sep 17 00:00:00 2001 From: Marcin Gordel Date: Wed, 20 Sep 2023 16:42:51 +0200 Subject: [PATCH] test(examples): fixed examples --- .../examples/composing-tasks/batch-end.mjs | 2 +- tests/examples/examples.test.ts | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/docs-examples/examples/composing-tasks/batch-end.mjs b/examples/docs-examples/examples/composing-tasks/batch-end.mjs index a0caa409e..8a5a9ebd0 100644 --- a/examples/docs-examples/examples/composing-tasks/batch-end.mjs +++ b/examples/docs-examples/examples/composing-tasks/batch-end.mjs @@ -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") diff --git a/tests/examples/examples.test.ts b/tests/examples/examples.test.ts index 783da6968..eaf1460bf 100644 --- a/tests/examples/examples.test.ts +++ b/tests/examples/examples.test.ts @@ -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) => { @@ -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); } }