taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 1dc8a2e268b93c2f24e3986890cb8e0b2e941ea4
parent ac2d2c6dde5b1815dd25b4bef97255bf9a41037b
Author: Florian Dold <florian@dold.me>
Date:   Wed, 23 Apr 2025 12:53:01 +0200

harness,wallet-core: improve logging, wait for txns with timeout

Diffstat:
Mpackages/taler-harness/src/integrationtests/test-peer-push.ts | 6++++++
Mpackages/taler-util/src/types-taler-wallet.ts | 2+-
Mpackages/taler-wallet-core/src/testing.ts | 18+++++++++++++++++-
Mpackages/taler-wallet-core/src/wallet.ts | 2+-
4 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-peer-push.ts b/packages/taler-harness/src/integrationtests/test-peer-push.ts @@ -325,6 +325,8 @@ export async function runPeerPushTest(t: GlobalTestState) { txState: { major: TransactionMajorState.Aborted, }, + logId: `exp-wallet1`, + timeout: { seconds: 10 }, }), // FIXME should be aborted wallet2.call(WalletApiOperation.TestingWaitTransactionState, { @@ -333,12 +335,16 @@ export async function runPeerPushTest(t: GlobalTestState) { major: TransactionMajorState.Pending, minor: TransactionMinorState.Merge, }, + logId: `exp-wallet2`, + timeout: { seconds: 10 }, }), wallet3.call(WalletApiOperation.TestingWaitTransactionState, { transactionId: prepare3.transactionId, txState: { major: TransactionMajorState.Aborted, }, + logId: `exp-wallet3`, + timeout: { seconds: 10 }, }), ]); } diff --git a/packages/taler-util/src/types-taler-wallet.ts b/packages/taler-util/src/types-taler-wallet.ts @@ -3600,7 +3600,7 @@ export interface TestingWaitTransactionRequest { * waiting for the desired state and raise * an error instead. */ - //timeout?: DurationUnitSpec; + timeout?: DurationUnitSpec; txState: TransactionStatePattern | TransactionStatePattern[]; } diff --git a/packages/taler-wallet-core/src/testing.ts b/packages/taler-wallet-core/src/testing.ts @@ -630,7 +630,22 @@ export async function waitTransactionState( txState, )}) (start logId: ${logId})`, ); - await genericWaitForState(wex, { + let timeoutPromise; + if (req.timeout != null) { + const durationMs = Duration.fromSpec(req.timeout).d_ms; + checkLogicInvariant(durationMs !== "forever"); + timeoutPromise = new Promise((resolve, reject) => { + wex.ws.timerGroup.after(durationMs, () => { + // Cancel the waiter. + wex.cts?.cancel(); + reject(new Error(`waiting timed out (timeout logId: ${logId}`)); + }); + }); + } else { + // No timeout => never resolve! + timeoutPromise = new Promise(() => {}); + } + const waitPromise = genericWaitForState(wex, { async checkState() { const tx = await getTransactionById(wex, { transactionId, @@ -655,6 +670,7 @@ export async function waitTransactionState( notif.type === NotificationType.TransactionStateTransition && notif.transactionId === transactionId, }); + await Promise.race([timeoutPromise, waitPromise]); logger.info( `done waiting for ${transactionId} to be in ${JSON.stringify( txState, diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts @@ -2876,7 +2876,7 @@ export class InternalWalletState { constructor( public dbImplementation: WalletDatabaseImplementation, private httpFactory: HttpFactory, - public timer: TimerAPI, + timer: TimerAPI, cryptoWorkerFactory: CryptoWorkerFactory, ) { this.cryptoDispatcher = new CryptoDispatcher(cryptoWorkerFactory);