diff options
author | Florian Dold <florian@dold.me> | 2024-03-06 11:02:13 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-03-06 11:02:13 +0100 |
commit | 541886750eb1bc32b9aa0323868dd24776baf0eb (patch) | |
tree | 39fd2c3eaf5a1f4b4d676f8f3568750be7763b17 /packages/taler-wallet-core/src/refresh.ts | |
parent | d10b46bffcef1599ba59538c69cc11499a852b4d (diff) | |
download | wallet-core-541886750eb1bc32b9aa0323868dd24776baf0eb.tar.xz |
taler-harness: test aborting refreshes
Diffstat (limited to 'packages/taler-wallet-core/src/refresh.ts')
-rw-r--r-- | packages/taler-wallet-core/src/refresh.ts | 85 |
1 files changed, 43 insertions, 42 deletions
diff --git a/packages/taler-wallet-core/src/refresh.ts b/packages/taler-wallet-core/src/refresh.ts index c6ece1536..9c272ad18 100644 --- a/packages/taler-wallet-core/src/refresh.ts +++ b/packages/taler-wallet-core/src/refresh.ts @@ -107,7 +107,7 @@ import { getCandidateWithdrawalDenomsTx } from "./withdraw.js"; const logger = new Logger("refresh.ts"); export class RefreshTransactionContext implements TransactionContext { - public transactionId: TransactionIdStr; + readonly transactionId: TransactionIdStr; readonly taskId: TaskIdStr; constructor( @@ -126,53 +126,54 @@ export class RefreshTransactionContext implements TransactionContext { async deleteTransaction(): Promise<void> { const refreshGroupId = this.refreshGroupId; - const ws = this.wex; - await ws.db.runReadWriteTx(["refreshGroups", "tombstones"], async (tx) => { - const rg = await tx.refreshGroups.get(refreshGroupId); - if (rg) { - await tx.refreshGroups.delete(refreshGroupId); - await tx.tombstones.put({ - id: TombstoneTag.DeleteRefreshGroup + ":" + refreshGroupId, - }); - } - }); + await this.wex.db.runReadWriteTx( + ["refreshGroups", "tombstones"], + async (tx) => { + const rg = await tx.refreshGroups.get(refreshGroupId); + if (rg) { + await tx.refreshGroups.delete(refreshGroupId); + await tx.tombstones.put({ + id: TombstoneTag.DeleteRefreshGroup + ":" + refreshGroupId, + }); + } + }, + ); } async suspendTransaction(): Promise<void> { const { wex, refreshGroupId, transactionId } = this; - let res = await wex.db.runReadWriteTx(["refreshGroups"], async (tx) => { - const dg = await tx.refreshGroups.get(refreshGroupId); - if (!dg) { - logger.warn( - `can't suspend refresh group, refreshGroupId=${refreshGroupId} not found`, - ); - return undefined; - } - const oldState = computeRefreshTransactionState(dg); - switch (dg.operationStatus) { - case RefreshOperationStatus.Finished: + let transitionInfo = await wex.db.runReadWriteTx( + ["refreshGroups"], + async (tx) => { + const dg = await tx.refreshGroups.get(refreshGroupId); + if (!dg) { + logger.warn( + `can't suspend refresh group, refreshGroupId=${refreshGroupId} not found`, + ); return undefined; - case RefreshOperationStatus.Pending: { - dg.operationStatus = RefreshOperationStatus.Suspended; - await tx.refreshGroups.put(dg); - return { - oldTxState: oldState, - newTxState: computeRefreshTransactionState(dg), - }; } - case RefreshOperationStatus.Suspended: - return undefined; - } - return undefined; - }); - if (res) { - wex.ws.notify({ - type: NotificationType.TransactionStateTransition, - transactionId, - oldTxState: res.oldTxState, - newTxState: res.newTxState, - }); - } + const oldState = computeRefreshTransactionState(dg); + switch (dg.operationStatus) { + case RefreshOperationStatus.Finished: + case RefreshOperationStatus.Suspended: + case RefreshOperationStatus.Failed: + return undefined; + case RefreshOperationStatus.Pending: { + dg.operationStatus = RefreshOperationStatus.Suspended; + await tx.refreshGroups.put(dg); + break; + } + default: + assertUnreachable(dg.operationStatus); + } + return { + oldTxState: oldState, + newTxState: computeRefreshTransactionState(dg), + }; + }, + ); + wex.taskScheduler.stopShepherdTask(this.taskId); + notifyTransition(wex, transactionId, transitionInfo); } async abortTransaction(): Promise<void> { |