From a59748a543a1317ab588647f34d61337e04682ce Mon Sep 17 00:00:00 2001 From: hatim boufnichel Date: Tue, 23 Apr 2024 18:13:06 +0200 Subject: [PATCH] fix --- src/services/main/applicationManager.ts | 6 ++++- src/services/main/index.ts | 5 ++++ src/services/main/paymentManager.ts | 4 ++++ src/tests/testBase.ts | 3 +-- src/tests/testRunner.ts | 31 ++++++++++++------------- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/services/main/applicationManager.ts b/src/services/main/applicationManager.ts index c58456fe4..0f2f6c82c 100644 --- a/src/services/main/applicationManager.ts +++ b/src/services/main/applicationManager.ts @@ -19,11 +19,12 @@ export default class { settings: MainSettings paymentManager: PaymentManager nPubLinkingTokens = new Map(); + linkingTokenInterval: NodeJS.Timeout constructor(storage: Storage, settings: MainSettings, paymentManager: PaymentManager) { this.storage = storage this.settings = settings this.paymentManager = paymentManager - setInterval(() => { + this.linkingTokenInterval = setInterval(() => { const now = Date.now(); for (let [token, data] of this.nPubLinkingTokens) { if (data.expiry <= now) { @@ -35,6 +36,9 @@ export default class { } }, 60 * 1000); // 1 minute } + Stop() { + clearInterval(this.linkingTokenInterval) + } SignAppToken(appId: string): string { return jwt.sign({ appId }, this.settings.jwtSecret); } diff --git a/src/services/main/index.ts b/src/services/main/index.ts index 3669db611..bf0bb05c7 100644 --- a/src/services/main/index.ts +++ b/src/services/main/index.ts @@ -50,6 +50,11 @@ export default class { this.appUserManager = new AppUserManager(this.storage, this.settings, this.applicationManager) } + Stop() { + this.lnd.Stop() + this.applicationManager.Stop() + this.paymentManager.Stop() + } attachNostrSend(f: NostrSend) { this.nostrSend = f diff --git a/src/services/main/paymentManager.ts b/src/services/main/paymentManager.ts index 94a474611..9f462e3b6 100644 --- a/src/services/main/paymentManager.ts +++ b/src/services/main/paymentManager.ts @@ -39,6 +39,7 @@ const defaultLnurlPayMetadata = `[["text/plain", "lnurl pay to Lightning.pub"]]` const confInOne = 1000 * 1000 const confInTwo = 100 * 1000 * 1000 export default class { + storage: Storage settings: MainSettings lnd: LightningHandler @@ -54,6 +55,9 @@ export default class { this.addressPaidCb = addressPaidCb this.invoicePaidCb = invoicePaidCb } + Stop() { + this.watchDog.Stop() + } getServiceFee(action: Types.UserOperationType, amount: number, appUser: boolean): number { switch (action) { diff --git a/src/tests/testBase.ts b/src/tests/testBase.ts index a33f8004c..a68d5376d 100644 --- a/src/tests/testBase.ts +++ b/src/tests/testBase.ts @@ -66,8 +66,7 @@ export const SetupTest = async (d: Describe): Promise => { } export const teardown = async (T: TestBase) => { - T.main.paymentManager.watchDog.Stop() - T.main.lnd.Stop() + T.main.Stop() T.externalAccessToMainLnd.Stop() T.externalAccessToOtherLnd.Stop() T.externalAccessToThirdLnd.Stop() diff --git a/src/tests/testRunner.ts b/src/tests/testRunner.ts index d68ba31fb..730adc53a 100644 --- a/src/tests/testRunner.ts +++ b/src/tests/testRunner.ts @@ -8,6 +8,16 @@ type TestModule = { default: (T: TestBase) => Promise } let failures = 0 +const getDescribe = (fileName: string): Describe => { + return (message, failure) => { + if (failure) { + failures++ + console.error(redConsole, fileName, ": FAILURE ", message, resetConsole) + } else { + console.log(greenConsole, fileName, ":", message, resetConsole) + } + } +} const start = async () => { const files = await globby("**/*.spec.js") @@ -19,8 +29,7 @@ const start = async () => { if (module.dev) { console.log("dev module found", file) if (devModule !== -1) { - console.error(redConsole, "there are multiple dev modules", resetConsole) - return + throw new Error("there are multiple dev modules") } devModule = modules.length - 1 } @@ -28,16 +37,15 @@ const start = async () => { if (devModule !== -1) { console.log("running dev module") await runTestFile(modules[devModule].file, modules[devModule].module) - return - } - else { + } else { console.log("running all tests") for (const { file, module } of modules) { await runTestFile(file, module) } } + console.log(failures) if (failures) { - console.error(redConsole, "there have been", `${failures}`, "failures in all tests", resetConsole) + throw new Error("there have been " + failures + " failures in all tests") } else { console.log(greenConsole, "there have been 0 failures in all tests", resetConsole) } @@ -69,16 +77,7 @@ const runTestFile = async (fileName: string, mod: TestModule) => { } } -const getDescribe = (fileName: string): Describe => { - return (message, failure) => { - if (failure) { - failures++ - console.error(redConsole, fileName, ": FAILURE ", message, resetConsole) - } else { - console.log(greenConsole, fileName, ":", message, resetConsole) - } - } -} + const greenConsole = "\x1b[32m" const redConsole = "\x1b[31m" const resetConsole = "\x1b[0m"