From 905dd538e5ccccbb56d5ab23bf135f6dec03e377 Mon Sep 17 00:00:00 2001 From: ConjunctiveNormalForm Date: Tue, 27 Aug 2024 19:02:43 -0400 Subject: [PATCH 1/2] use allSettled instead so that we dont throw --- lib/quoters/WebhookQuoter.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/quoters/WebhookQuoter.ts b/lib/quoters/WebhookQuoter.ts index 60bc822..5cc3a4d 100644 --- a/lib/quoters/WebhookQuoter.ts +++ b/lib/quoters/WebhookQuoter.ts @@ -24,6 +24,7 @@ import { timestampInMstoISOString } from '../util/time'; // TODO: shorten, maybe take from env config const WEBHOOK_TIMEOUT_MS = 500; +const NOTIFICATION_TIMEOUT_MS = 10; // Quoter which fetches quotes from http endpoints // endpoints must return well-formed QuoteResponse JSON @@ -60,7 +61,7 @@ export class WebhookQuoter implements Quoter { const quotes = await Promise.all(enabledEndpoints.map((e) => this.fetchQuote(e, request))); // should not await and block - Promise.all(disabledEndpoints.map((e) => this.notifyBlock(e))); + Promise.allSettled(disabledEndpoints.map((e) => this.notifyBlock(e))); return quotes.filter((q) => q !== null) as QuoteResponse[]; } @@ -310,9 +311,8 @@ export class WebhookQuoter implements Quoter { } private async notifyBlock(status: { webhook: WebhookConfiguration; blockUntil: number }): Promise { - const timeoutOverride = status.webhook.overrides?.timeout; const axiosConfig = { - timeout: timeoutOverride ? Number(timeoutOverride) : WEBHOOK_TIMEOUT_MS, + timeout: NOTIFICATION_TIMEOUT_MS, ...(!!status.webhook.headers && { headers: status.webhook.headers }), }; try { From 96d6366a98feda05aeb7c74795a632db453a767c Mon Sep 17 00:00:00 2001 From: ConjunctiveNormalForm Date: Wed, 28 Aug 2024 10:29:33 -0400 Subject: [PATCH 2/2] fix unit tests --- lib/constants.ts | 3 +++ lib/quoters/WebhookQuoter.ts | 5 +---- test/providers/quoters/WebhookQuoter.test.ts | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/constants.ts b/lib/constants.ts index 9903bdc..d5b2952 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -34,3 +34,6 @@ export const DYNAMO_TABLE_KEY = { export const POST_ORDER_ERROR_REASON = { INSUFFICIENT_FUNDS: 'Onchain validation failed: InsufficientFunds', }; + +export const WEBHOOK_TIMEOUT_MS = 500; +export const NOTIFICATION_TIMEOUT_MS = 10; diff --git a/lib/quoters/WebhookQuoter.ts b/lib/quoters/WebhookQuoter.ts index 5cc3a4d..4342238 100644 --- a/lib/quoters/WebhookQuoter.ts +++ b/lib/quoters/WebhookQuoter.ts @@ -5,6 +5,7 @@ import Logger from 'bunyan'; import { v4 as uuidv4 } from 'uuid'; import { Quoter, QuoterType } from '.'; +import { NOTIFICATION_TIMEOUT_MS, WEBHOOK_TIMEOUT_MS } from '../constants'; import { AnalyticsEvent, AnalyticsEventType, @@ -22,10 +23,6 @@ import { FillerComplianceConfigurationProvider } from '../providers/compliance'; import { FillerAddressRepository } from '../repositories/filler-address-repository'; import { timestampInMstoISOString } from '../util/time'; -// TODO: shorten, maybe take from env config -const WEBHOOK_TIMEOUT_MS = 500; -const NOTIFICATION_TIMEOUT_MS = 10; - // Quoter which fetches quotes from http endpoints // endpoints must return well-formed QuoteResponse JSON export class WebhookQuoter implements Quoter { diff --git a/test/providers/quoters/WebhookQuoter.test.ts b/test/providers/quoters/WebhookQuoter.test.ts index 3b3726d..2568f70 100644 --- a/test/providers/quoters/WebhookQuoter.test.ts +++ b/test/providers/quoters/WebhookQuoter.test.ts @@ -2,6 +2,7 @@ import { TradeType } from '@uniswap/sdk-core'; import axios from 'axios'; import { BigNumber, ethers } from 'ethers'; +import { NOTIFICATION_TIMEOUT_MS } from '../../../lib/constants'; import { AnalyticsEventType, QuoteRequest, WebhookResponseType } from '../../../lib/entities'; import { MockWebhookConfigurationProvider, ProtocolVersion } from '../../../lib/providers'; import { FirehoseLogger } from '../../../lib/providers/analytics'; @@ -262,7 +263,7 @@ describe('WebhookQuoter tests', () => { }, { headers: {}, - timeout: 500, + timeout: NOTIFICATION_TIMEOUT_MS, } ); }); @@ -306,10 +307,11 @@ describe('WebhookQuoter tests', () => { }); await webhookQuoter.quote(request); + // blocked expect(mockedAxios.post).toBeCalledWith( WEBHOOK_URL_ONEINCH, { blockUntilTimestamp: expect.any(Number) }, - { headers: {}, timeout: 500 } + { headers: {}, timeout: NOTIFICATION_TIMEOUT_MS } ); expect(mockedAxios.post).toBeCalledWith( WEBHOOK_URL_SEARCHER,