diff options
author | Florian Dold <florian@dold.me> | 2022-10-05 15:45:10 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-10-05 15:45:28 +0200 |
commit | 70d37e4ed30e69c4b3ba2d31a50fd61d82b91252 (patch) | |
tree | 7f5d2741886e3cd31c41d81a40ca12670fde36a9 /packages/taler-wallet-core/src | |
parent | efc4ac8dca3f4163aca5e208b7c35cdde140793d (diff) | |
download | wallet-core-70d37e4ed30e69c4b3ba2d31a50fd61d82b91252.tar.xz |
integration tests: test crypto worker
We test instantiations of both crypto workers that are available for
node.
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/crypto/workers/cryptoDispatcher.ts | 7 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/headless/helpers.ts | 9 |
2 files changed, 13 insertions, 3 deletions
diff --git a/packages/taler-wallet-core/src/crypto/workers/cryptoDispatcher.ts b/packages/taler-wallet-core/src/crypto/workers/cryptoDispatcher.ts index 85f9acddc..1c0d509e6 100644 --- a/packages/taler-wallet-core/src/crypto/workers/cryptoDispatcher.ts +++ b/packages/taler-wallet-core/src/crypto/workers/cryptoDispatcher.ts @@ -15,7 +15,8 @@ */ /** - * API to access the Taler crypto worker thread. + * API to access the Taler crypto worker. + * * @author Florian Dold */ @@ -76,6 +77,10 @@ interface WorkItem { */ const NUM_PRIO = 5; +/** + * A crypto worker factory is responsible for creating new + * crypto workers on-demand. + */ export interface CryptoWorkerFactory { /** * Start a new worker. diff --git a/packages/taler-wallet-core/src/headless/helpers.ts b/packages/taler-wallet-core/src/headless/helpers.ts index 63967d4ad..2be9be9a1 100644 --- a/packages/taler-wallet-core/src/headless/helpers.ts +++ b/packages/taler-wallet-core/src/headless/helpers.ts @@ -61,6 +61,8 @@ export interface DefaultNodeWalletArgs { * of the default one. */ httpLib?: HttpRequestLibrary; + + cryptoWorkerType?: "sync" | "node-worker-thread"; } /** @@ -160,10 +162,11 @@ export async function getDefaultNodeWallet2( const myDb = await openTalerDatabase(myIdbFactory, myVersionChange); let workerFactory; - if (process.env["TALER_WALLET_SYNC_CRYPTO"]) { + const cryptoWorkerType = args.cryptoWorkerType ?? "node-worker-thread"; + if (cryptoWorkerType === "sync") { logger.info("using synchronous crypto worker"); workerFactory = new SynchronousCryptoWorkerFactory(); - } else { + } else if (cryptoWorkerType === "node-worker-thread") { try { // Try if we have worker threads available, fails in older node versions. const _r = "require"; @@ -177,6 +180,8 @@ export async function getDefaultNodeWallet2( ); workerFactory = new SynchronousCryptoWorkerFactory(); } + } else { + throw Error(`unsupported crypto worker type '${cryptoWorkerType}'`); } const timer = new SetTimeoutTimerAPI(); |