From 5a286c1796d0cb19cdef231ab1d312f1b5d73be4 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 11 Oct 2022 11:08:53 +0200 Subject: [PATCH] fix: not abort when no winner (#95) --- packages/edge-gateway/src/gateway.js | 14 +++++++------- packages/edge-gateway/test/index.spec.js | 13 +++++++++++++ packages/edge-gateway/test/utils/miniflare.js | 1 + 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/edge-gateway/src/gateway.js b/packages/edge-gateway/src/gateway.js index f7ebcf9..bf8148b 100644 --- a/packages/edge-gateway/src/gateway.js +++ b/packages/edge-gateway/src/gateway.js @@ -403,15 +403,15 @@ async function reportRaceResults (env, gatewayResponsePromises, winnerUrl, gatew }) ) - // Abort all on going requests except for the winner - for (const [gatewayUrl, controller] of Object.entries(gatewayControllers)) { - if (winnerUrl !== gatewayUrl) { - controller.abort() + if (winnerUrl) { + // Abort all on going requests except for the winner + for (const [gatewayUrl, controller] of Object.entries(gatewayControllers)) { + if (winnerUrl !== gatewayUrl) { + controller.abort() + } } - } - // Count winners - if (winnerUrl) { + // Count winners env.PUBLIC_RACE_WINNER.writeDataPoint({ blobs: [winnerUrl], doubles: [1] diff --git a/packages/edge-gateway/test/index.spec.js b/packages/edge-gateway/test/index.spec.js index 1ebd5a2..5212d59 100644 --- a/packages/edge-gateway/test/index.spec.js +++ b/packages/edge-gateway/test/index.spec.js @@ -101,3 +101,16 @@ test('Gets content with other base encodings', async (t) => { await response.waitUntil() t.is(await response.text(), 'Hello dot.storage! 😎') }) + +test('Gets response error when all fail to resolve', async (t) => { + const { mf } = t.context + + const cidStr = 'bafkreibehzafi6gdvlyue5lzxa3rfobvp452kylox6f4vwqpd4xbr54uqu' + + const response = await mf.dispatchFetch( + `https://${cidStr}.ipfs.localhost:8787` + ) + await response.waitUntil() + const body = await response.text() + t.assert(body) +}) diff --git a/packages/edge-gateway/test/utils/miniflare.js b/packages/edge-gateway/test/utils/miniflare.js index 46f717a..f0bddee 100644 --- a/packages/edge-gateway/test/utils/miniflare.js +++ b/packages/edge-gateway/test/utils/miniflare.js @@ -40,6 +40,7 @@ export function getMiniflare (bindings = {}) { PUBLIC_RACE_WINNER: createAnalyticsEngine(), PUBLIC_RACE_TTFB: createAnalyticsEngine(), PUBLIC_RACE_STATUS_CODE: createAnalyticsEngine(), + REQUEST_TIMEOUT: 3000, ...bindings } })