taler-harness: clean up shared test env on start

This commit is contained in:
Florian Dold 2023-08-29 10:16:18 +02:00
parent 55bdc161b5
commit 9402aeef5b
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 41 additions and 5 deletions

View File

@ -215,10 +215,14 @@ export async function createSimpleTestkudosEnvironment(
}; };
} }
export function getSharedTestDir(): string {
return `/tmp/taler-harness@${process.env.USER}`;
}
export async function useSharedTestkudosEnvironment(t: GlobalTestState) { export async function useSharedTestkudosEnvironment(t: GlobalTestState) {
const coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("TESTKUDOS")); const coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("TESTKUDOS"));
const sharedDir = `/tmp/taler-harness@${process.env.USER}`; const sharedDir = getSharedTestDir();
fs.mkdirSync(sharedDir, { recursive: true }); fs.mkdirSync(sharedDir, { recursive: true });
@ -230,10 +234,9 @@ export async function useSharedTestkudosEnvironment(t: GlobalTestState) {
logger.info(`previous setup done: ${prevSetupDone}`); logger.info(`previous setup done: ${prevSetupDone}`);
// Wallet has longer startup-time and no dependencies, // Wallet has longer startup-time and no dependencies,
// so we start it rather early. // so we start it rather early.
const walletStartProm = createWalletDaemonWithClient(t, { name: "wallet" }) const walletStartProm = createWalletDaemonWithClient(t, { name: "wallet" });
if (fs.existsSync(sharedDir + "/bank.conf")) { if (fs.existsSync(sharedDir + "/bank.conf")) {
logger.info("reusing existing bank"); logger.info("reusing existing bank");
@ -361,7 +364,7 @@ export async function useSharedTestkudosEnvironment(t: GlobalTestState) {
} }
}; };
await bankStart() await bankStart();
const res = await Promise.all([ const res = await Promise.all([
exchangeStart(), exchangeStart(),

View File

@ -27,10 +27,12 @@ import * as path from "path";
import url from "url"; import url from "url";
import { import {
GlobalTestState, GlobalTestState,
runCommand,
runTestWithState, runTestWithState,
shouldLingerInTest, shouldLingerInTest,
TestRunResult, TestRunResult,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { spawnSync } from "child_process";
import { runAgeRestrictionsMerchantTest } from "./test-age-restrictions-merchant.js"; import { runAgeRestrictionsMerchantTest } from "./test-age-restrictions-merchant.js";
import { runBankApiTest } from "./test-bank-api.js"; import { runBankApiTest } from "./test-bank-api.js";
import { runClaimLoopTest } from "./test-claim-loop.js"; import { runClaimLoopTest } from "./test-claim-loop.js";
@ -111,6 +113,7 @@ import { runPaymentShareTest } from "./test-payment-share.js";
import { runSimplePaymentTest } from "./test-simple-payment.js"; import { runSimplePaymentTest } from "./test-simple-payment.js";
import { runTermOfServiceFormatTest } from "./test-tos-format.js"; import { runTermOfServiceFormatTest } from "./test-tos-format.js";
import { runExchangePurseTest } from "./test-exchange-purse.js"; import { runExchangePurseTest } from "./test-exchange-purse.js";
import { getSharedTestDir } from "../harness/helpers.js";
/** /**
* Test runner. * Test runner.
@ -264,7 +267,37 @@ interface RunTestChildInstruction {
testRootDir: string; testRootDir: string;
} }
function purgeSharedTestEnvironment() {
const rmRes = spawnSync("rm", ["-rf", `${getSharedTestDir()}`]);
if (rmRes.status != 0) {
logger.warn("can't delete shared test directory");
}
const psqlRes = spawnSync("psql", ["-Aqtl"], {
encoding: "utf-8",
});
if (psqlRes.status != 0) {
logger.warn("could not list available postgres databases");
return;
}
if (psqlRes.output[1]!!.indexOf("taler-integrationtest-shared") >= 0) {
const dropRes = spawnSync("dropdb", ["taler-integrationtest-shared"], {
encoding: "utf-8",
});
if (dropRes.status != 0) {
logger.warn("could not drop taler-integrationtest-shared database");
return;
}
}
}
export async function runTests(spec: TestRunSpec) { export async function runTests(spec: TestRunSpec) {
if (!process.env.TALER_HARNESS_KEEP) {
logger.info("purging shared test environment");
purgeSharedTestEnvironment();
} else {
logger.info("keeping shared test environment");
}
const testRootDir = fs.mkdtempSync( const testRootDir = fs.mkdtempSync(
path.join(os.tmpdir(), "taler-integrationtests-"), path.join(os.tmpdir(), "taler-integrationtests-"),
); );