From 3277caa38a693e7faae588133d2604cd7072295a Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 13 Jan 2024 14:24:28 +0100 Subject: wallet-core: test request to diagnose sleep/wakeup issue on iOS --- packages/taler-wallet-core/src/db.ts | 5 ++++- packages/taler-wallet-core/src/wallet-api-types.ts | 10 ++++++---- packages/taler-wallet-core/src/wallet.ts | 21 ++++++++++++++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) (limited to 'packages') diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 549bc7517..263de9d4c 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -1324,6 +1324,8 @@ export enum ConfigRecordKey { WalletBackupState = "walletBackupState", CurrencyDefaultsApplied = "currencyDefaultsApplied", DevMode = "devMode", + // Only for testing, do not use! + TestLoopTx = "testTxLoop", } /** @@ -1336,7 +1338,8 @@ export type ConfigRecord = value: WalletBackupConfState; } | { key: ConfigRecordKey.CurrencyDefaultsApplied; value: boolean } - | { key: ConfigRecordKey.DevMode; value: boolean }; + | { key: ConfigRecordKey.DevMode; value: boolean } + | { key: ConfigRecordKey.TestLoopTx; value: number }; export interface WalletBackupConfState { deviceId: string; diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts index a4be0f448..7ac347b6d 100644 --- a/packages/taler-wallet-core/src/wallet-api-types.ts +++ b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -234,6 +234,7 @@ export enum WalletApiOperation { TestingWaitTasksProcessed = "testingWaitTasksProcessed", ListExchangesForScopedCurrency = "listExchangesForScopedCurrency", PrepareWithdrawExchange = "prepareWithdrawExchange", + TestingInfiniteTransactionLoop = "testingInfiniteTransactionLoop", } // group: Initialization @@ -1194,6 +1195,7 @@ export type WalletOperations = { [WalletApiOperation.RecoverStoredBackup]: RecoverStoredBackupsOp; [WalletApiOperation.UpdateExchangeEntry]: UpdateExchangeEntryOp; [WalletApiOperation.PrepareWithdrawExchange]: PrepareWithdrawExchangeOp; + [WalletApiOperation.TestingInfiniteTransactionLoop]: any; }; export type WalletCoreRequestType< @@ -1219,8 +1221,8 @@ type RecursivePartial = { [P in keyof T]?: T[P] extends Array ? Array> : T[P] extends Array - ? Array - : T[P] extends object - ? RecursivePartial - : T[P]; + ? Array + : T[P] extends object + ? RecursivePartial + : T[P]; } & object; diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index da34ff37f..8d5028d47 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -298,7 +298,7 @@ import { GetReadOnlyAccess, GetReadWriteAccess, } from "./util/query.js"; -import { TimerAPI, TimerGroup } from "./util/timer.js"; +import { TimerAPI, TimerGroup, timer } from "./util/timer.js"; import { WALLET_BANK_CONVERSION_API_PROTOCOL_VERSION, WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, @@ -1393,6 +1393,25 @@ async function dispatchRequestInternal( ws.workAvailable.trigger(); return {}; } + case WalletApiOperation.TestingInfiniteTransactionLoop: { + const myDelayMs = (payload as any).delayMs ?? 5; + let loopCount = 0; + while (true) { + logger.info(`looping test write tx, iteration ${loopCount}`); + await ws.db.runReadWriteTx(["config"], async (tx) => { + await tx.config.put({ + key: ConfigRecordKey.TestLoopTx, + value: loopCount, + }); + }); + if (myDelayMs != 0) { + await new Promise((resolve, reject) => { + setTimeout(() => resolve(), myDelayMs); + }); + } + loopCount = (loopCount + 1) % (Number.MAX_SAFE_INTEGER - 1); + } + } // default: // assertUnreachable(operation); } -- cgit v1.2.3