From 5f62d83a4ddab49a20ed29221c204dff5fe52b6d Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 1 Aug 2019 23:21:15 +0200 Subject: headless/android port, PoC for CLI / headless tests --- src/crypto/cryptoApi.ts | 19 ++++++++++++++++++- src/crypto/nodeWorker.ts | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src/crypto') diff --git a/src/crypto/cryptoApi.ts b/src/crypto/cryptoApi.ts index d3a93ff8d..5e3237836 100644 --- a/src/crypto/cryptoApi.ts +++ b/src/crypto/cryptoApi.ts @@ -41,6 +41,7 @@ import { BenchmarkResult, CoinWithDenom, PayCoinInfo } from "../walletTypes"; import * as timer from "../timer"; import { startWorker } from "./startWorker"; +import { throws } from "assert"; /** * State of a crypto worker. @@ -98,6 +99,11 @@ export class CryptoApi { */ private numBusy: number = 0; + /** + * Did we stop accepting new requests? + */ + private stopped: boolean = false; + public enableTracing = false; /** @@ -106,6 +112,7 @@ export class CryptoApi { terminateWorkers() { for (let worker of this.workers) { if (worker.w) { + this.enableTracing && console.log("terminating worker"); worker.w.terminate(); if (worker.terminationTimerHandle) { worker.terminationTimerHandle.clear(); @@ -120,10 +127,19 @@ export class CryptoApi { } } + stop() { + this.terminateWorkers(); + this.stopped = true; + } + /** * Start a worker (if not started) and set as busy. */ wake(ws: WorkerState, work: WorkItem): void { + if (this.stopped) { + this.enableTracing && console.log("not waking, as cryptoApi is stopped"); + return; + } if (ws.currentWorkItem !== null) { throw Error("assertion failed"); } @@ -158,7 +174,7 @@ export class CryptoApi { ws.w = null; } }; - ws.terminationTimerHandle = timer.after(5 * 1000, destroy); + ws.terminationTimerHandle = timer.after(15 * 1000, destroy); } handleWorkerError(ws: WorkerState, e: ErrorEvent) { @@ -253,6 +269,7 @@ export class CryptoApi { priority: number, ...args: any[] ): Promise { + this.enableTracing && console.log("cryptoApi: doRpc called"); const p: Promise = new Promise((resolve, reject) => { const rpcId = this.nextRpcId++; const workItem: WorkItem = { diff --git a/src/crypto/nodeWorker.ts b/src/crypto/nodeWorker.ts index fa942387a..b5a2e8b44 100644 --- a/src/crypto/nodeWorker.ts +++ b/src/crypto/nodeWorker.ts @@ -92,6 +92,7 @@ export class Worker { * Forcibly terminate the worker thread. */ terminate () { + console.log("terminating node.js worker"); this.child.kill("SIGINT"); } } -- cgit v1.2.3