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 | |
parent | c0904936e4b9f940e9f036d203832fed21994bb7 (diff) | |
download | wallet-core-aefc3f26b673c38fa1ca8238c049d2739063069c.tar.xz |
timeout for tests
Diffstat (limited to 'packages')
-rw-r--r-- | packages/taler-wallet-cli/package.json | 3 | ||||
-rw-r--r-- | packages/taler-wallet-cli/src/integrationtests/harness.ts | 8 | ||||
-rw-r--r-- | packages/taler-wallet-cli/src/integrationtests/testrunner.ts | 84 |
3 files changed, 69 insertions, 26 deletions
diff --git a/packages/taler-wallet-cli/package.json b/packages/taler-wallet-cli/package.json index 63f5fc25e..993723278 100644 --- a/packages/taler-wallet-cli/package.json +++ b/packages/taler-wallet-cli/package.json @@ -44,11 +44,12 @@ "typescript": "^4.1.3" }, "dependencies": { + "@gnu-taler/taler-wallet-core": "workspace:*", "@types/minimatch": "^3.0.3", "axios": "^0.21.1", + "cancellationtoken": "^2.2.0", "minimatch": "^3.0.4", "source-map-support": "^0.5.19", - "@gnu-taler/taler-wallet-core": "workspace:*", "tslib": "^2.1.0" } } diff --git a/packages/taler-wallet-cli/src/integrationtests/harness.ts b/packages/taler-wallet-cli/src/integrationtests/harness.ts index bd950da0b..9a1136bc0 100644 --- a/packages/taler-wallet-cli/src/integrationtests/harness.ts +++ b/packages/taler-wallet-cli/src/integrationtests/harness.ts @@ -98,10 +98,14 @@ import { import { ApplyRefundResponse } from "@gnu-taler/taler-wallet-core"; import { PendingOperationsResponse } from "@gnu-taler/taler-wallet-core"; import { CoinConfig } from "./denomStructures"; +import CancellationToken from "cancellationtoken"; const exec = util.promisify(require("child_process").exec); -export async function delayMs(ms: number): Promise<void> { +export async function delayMs( + ms: number, + cancellationToken?: CancellationToken, +): Promise<void> { return new Promise((resolve, reject) => { setTimeout(() => resolve(), ms); }); @@ -1486,6 +1490,8 @@ export interface TestRunResult { timeSec: number; status: TestStatus; + + reason?: string; } export async function runTestWithState( 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(); |