mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2024-12-24 23:09:26 -05:00
catch errors starting havenods and shut down gracefully
This commit is contained in:
parent
490f1e8c22
commit
9f3ff5c2ce
@ -297,6 +297,7 @@ const OFFLINE_ERR_MSG = "Http response at 400 or 500 level";
|
|||||||
jest.setTimeout(TestConfig.testTimeout);
|
jest.setTimeout(TestConfig.testTimeout);
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
try {
|
||||||
|
|
||||||
// set log level for tests
|
// set log level for tests
|
||||||
HavenoUtils.setLogLevel(TestConfig.logLevel);
|
HavenoUtils.setLogLevel(TestConfig.logLevel);
|
||||||
@ -317,11 +318,13 @@ beforeAll(async () => {
|
|||||||
|
|
||||||
// start configured haveno daemons
|
// start configured haveno daemons
|
||||||
const promises: Promise<HavenoClient>[] = [];
|
const promises: Promise<HavenoClient>[] = [];
|
||||||
|
let err;
|
||||||
for (const config of TestConfig.startupHavenods) promises.push(initHaveno(config));
|
for (const config of TestConfig.startupHavenods) promises.push(initHaveno(config));
|
||||||
for (const settledPromise of await Promise.allSettled(promises)) {
|
for (const settledPromise of await Promise.allSettled(promises)) {
|
||||||
if (settledPromise.status !== "fulfilled") throw new Error((settledPromise as PromiseRejectedResult).reason);
|
if (settledPromise.status === "fulfilled") startupHavenods.push((settledPromise as PromiseFulfilledResult<HavenoClient>).value);
|
||||||
startupHavenods.push((settledPromise as PromiseFulfilledResult<HavenoClient>).value);
|
else if (!err) err = new Error((settledPromise as PromiseRejectedResult).reason);
|
||||||
}
|
}
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
// assign arbitrator, user1, user2
|
// assign arbitrator, user1, user2
|
||||||
arbitrator = startupHavenods[0];
|
arbitrator = startupHavenods[0];
|
||||||
@ -340,6 +343,10 @@ beforeAll(async () => {
|
|||||||
|
|
||||||
// create test data directory if it doesn't exist
|
// create test data directory if it doesn't exist
|
||||||
if (!fs.existsSync(TestConfig.testDataDir)) fs.mkdirSync(TestConfig.testDataDir);
|
if (!fs.existsSync(TestConfig.testDataDir)) fs.mkdirSync(TestConfig.testDataDir);
|
||||||
|
} catch (err) {
|
||||||
|
await shutDown();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@ -347,6 +354,10 @@ beforeEach(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
await shutDown();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function shutDown() {
|
||||||
|
|
||||||
// release haveno processes
|
// release haveno processes
|
||||||
const promises: Promise<void>[] = [];
|
const promises: Promise<void>[] = [];
|
||||||
@ -357,7 +368,7 @@ afterAll(async () => {
|
|||||||
|
|
||||||
// terminate monero-javascript worker
|
// terminate monero-javascript worker
|
||||||
(await monerojs.LibraryUtils.getWorker()).terminate();
|
(await monerojs.LibraryUtils.getWorker()).terminate();
|
||||||
});
|
}
|
||||||
|
|
||||||
// ----------------------------------- TESTS ----------------------------------
|
// ----------------------------------- TESTS ----------------------------------
|
||||||
|
|
||||||
@ -2733,7 +2744,14 @@ async function initHaveno(ctx?: HavenodContext): Promise<HavenoClient> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// open account if configured
|
// open account if configured
|
||||||
if (ctx.autoLogin) await initHavenoAccount(havenod, ctx.accountPassword!);
|
if (ctx.autoLogin) {
|
||||||
|
try {
|
||||||
|
await initHavenoAccount(havenod, ctx.accountPassword!);
|
||||||
|
} catch (err) {
|
||||||
|
await releaseHavenoProcess(havenod);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
return havenod;
|
return havenod;
|
||||||
|
|
||||||
async function getAvailablePort(): Promise<number> {
|
async function getAvailablePort(): Promise<number> {
|
||||||
|
Loading…
Reference in New Issue
Block a user