Skip to content

Commit

Permalink
fix: not abort when no winner (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored Oct 11, 2022
1 parent 8768355 commit 5a286c1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/edge-gateway/src/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 13 additions & 0 deletions packages/edge-gateway/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
1 change: 1 addition & 0 deletions packages/edge-gateway/test/utils/miniflare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
Expand Down

0 comments on commit 5a286c1

Please sign in to comment.