From 883637d3f287e5026de5bcafb559ff3e6ba1f3bb Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 8 Feb 2021 13:02:12 +0100 Subject: allow fault injection callbacks to run async code --- .../src/integrationtests/faultInjection.ts | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'packages/taler-wallet-cli/src/integrationtests/faultInjection.ts') diff --git a/packages/taler-wallet-cli/src/integrationtests/faultInjection.ts b/packages/taler-wallet-cli/src/integrationtests/faultInjection.ts index a2d4836d9..60549154b 100644 --- a/packages/taler-wallet-cli/src/integrationtests/faultInjection.ts +++ b/packages/taler-wallet-cli/src/integrationtests/faultInjection.ts @@ -28,17 +28,10 @@ import { URL } from "url"; import { GlobalTestState, ExchangeService, - BankService, ExchangeServiceInterface, MerchantServiceInterface, MerchantService, - PrivateOrderStatusQuery, } from "./harness"; -import { - PostOrderRequest, - PostOrderResponse, - MerchantOrderPrivateStatusResponse, -} from "./merchantApiTypes"; export interface FaultProxyConfig { inboundPort: number; @@ -65,8 +58,8 @@ export interface FaultInjectionResponseContext { } export interface FaultSpec { - modifyRequest?: (ctx: FaultInjectionRequestContext) => void; - modifyResponse?: (ctx: FaultInjectionResponseContext) => void; + modifyRequest?: (ctx: FaultInjectionRequestContext) => Promise; + modifyResponse?: (ctx: FaultInjectionResponseContext) => Promise; } export class FaultProxy { @@ -85,7 +78,7 @@ export class FaultProxy { req.on("data", (chunk) => { requestChunks.push(chunk); }); - req.on("end", () => { + req.on("end", async () => { console.log("end of data"); let requestBuffer: Buffer | undefined; if (requestChunks.length > 0) { @@ -103,7 +96,7 @@ export class FaultProxy { for (const faultSpec of this.currentFaultSpecs) { if (faultSpec.modifyRequest) { - faultSpec.modifyRequest(faultReqContext); + await faultSpec.modifyRequest(faultReqContext); } } @@ -138,7 +131,7 @@ export class FaultProxy { proxyResp.on("data", (proxyRespData) => { respChunks.push(proxyRespData); }); - proxyResp.on("end", () => { + proxyResp.on("end", async () => { console.log("end of target response"); let responseBuffer: Buffer | undefined; if (respChunks.length > 0) { @@ -154,7 +147,7 @@ export class FaultProxy { for (const faultSpec of this.currentFaultSpecs) { const modResponse = faultSpec.modifyResponse; if (modResponse) { - modResponse(faultRespContext); + await modResponse(faultRespContext); } } if (faultRespContext.dropResponse) { -- cgit v1.2.3