diff options
author | Florian Dold <florian@dold.me> | 2021-02-04 15:07:47 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-02-04 15:08:08 +0100 |
commit | aefc3f26b673c38fa1ca8238c049d2739063069c (patch) | |
tree | 4334506b715cc51b03b23eb435422d0fb7ff9429 /packages/taler-wallet-cli/src/integrationtests/testrunner.ts | |
parent | c0904936e4b9f940e9f036d203832fed21994bb7 (diff) | |
download | wallet-core-aefc3f26b673c38fa1ca8238c049d2739063069c.tar.xz |
timeout for tests
Diffstat (limited to 'packages/taler-wallet-cli/src/integrationtests/testrunner.ts')
-rw-r--r-- | packages/taler-wallet-cli/src/integrationtests/testrunner.ts | 84 |
1 files changed, 60 insertions, 24 deletions
diff --git a/packages/taler-wallet-cli/src/integrationtests/testrunner.ts b/packages/taler-wallet-cli/src/integrationtests/testrunner.ts index e820ac25a..77d974f27 100644 --- a/packages/taler-wallet-cli/src/integrationtests/testrunner.ts +++ b/packages/taler-wallet-cli/src/integrationtests/testrunner.ts @@ -15,6 +15,7 @@ */ import { + delayMs, GlobalTestState, runTestWithState, shouldLingerInTest, @@ -56,6 +57,7 @@ import { runMerchantExchangeConfusionTest } from "./test-merchant-exchange-confu import { runLibeufinBasicTest } from "./test-libeufin-basic"; import { runLibeufinTutorialTest } from "./test-libeufin-tutorial"; import { runDepositTest } from "./test-deposit"; +import CancellationToken from "cancellationtoken"; /** * Test runner. @@ -201,30 +203,64 @@ export async function runTests(spec: TestRunSpec) { currentChild.stdout?.pipe(harnessLogStream); currentChild.stderr?.pipe(harnessLogStream); - const result: TestRunResult = await new Promise((resolve, reject) => { - let msg: TestRunResult | undefined; - currentChild!.on("message", (m) => { - msg = m as TestRunResult; - }); - currentChild!.on("exit", (code, signal) => { - if (signal) { - reject(new Error(`test worker exited with signal ${signal}`)); - } else if (code != 0) { - reject(new Error(`test worker exited with code ${code}`)); - } else if (!msg) { - reject( - new Error( - `test worker exited without giving back the test results`, - ), - ); - } else { - resolve(msg); - } - }); - currentChild!.on("error", (err) => { - reject(err); - }); - }); + const testTimeoutMs = 60000; + + const { token } = CancellationToken.timeout(60000); + + const resultPromise: Promise<TestRunResult> = new Promise( + (resolve, reject) => { + let msg: TestRunResult | undefined; + currentChild!.on("message", (m) => { + if (token.isCancelled) { + return; + } + msg = m as TestRunResult; + }); + currentChild!.on("exit", (code, signal) => { + if (token.isCancelled) { + return; + } + if (signal) { + reject(new Error(`test worker exited with signal ${signal}`)); + } else if (code != 0) { + reject(new Error(`test worker exited with code ${code}`)); + } else if (!msg) { + reject( + new Error( + `test worker exited without giving back the test results`, + ), + ); + } else { + resolve(msg); + } + }); + currentChild!.on("error", (err) => { + if (token.isCancelled) { + return; + } + reject(err); + }); + }, + ); + + let result: TestRunResult; + + try { + result = await token.racePromise(resultPromise); + } catch (e) { + console.error(`test ${testName} timed out`); + if (token.isCancelled) { + result = { + status: "fail", + reason: "timeout", + timeSec: testTimeoutMs / 1000, + name: testName, + }; + currentChild.kill("SIGTERM"); + } else { + throw Error(e); + } + } harnessLogStream.close(); |