Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 12 additions & 18 deletions tests/integration/commands/deploy/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { afterAll, beforeAll, describe, expect, test } from 'vitest'

import { callCli } from '../../utils/call-cli.js'
import { createLiveTestSite, generateSiteName } from '../../utils/create-live-test-site.js'
import { fetchWithRetry } from '../../utils/fetch-with-retry.js'
import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.js'
import { pause } from '../../utils/pause.js'
import { withSiteBuilder } from '../../utils/site-builder.js'
Expand Down Expand Up @@ -863,7 +864,7 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
true,
)) as unknown as Deploy

const response = await fetch(`${deployUrl}/.netlify/functions/hello`)
const response = await fetchWithRetry(`${deployUrl}/.netlify/functions/hello`)
t.expect(await response.text()).toEqual('Hello')
t.expect(response.status).toBe(200)
})
Expand Down Expand Up @@ -973,19 +974,6 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
true,
)) as unknown as Deploy

// Add retry logic for fetching deployed functions
const fetchWithRetry = async (url: string, maxRetries = 5) => {
for (let i = 0; i < maxRetries; i++) {
try {
return await fetch(url)
} catch (error) {
if (i === maxRetries - 1) throw error
await pause(2000 * (i + 1)) // Exponential backoff: 2s, 4s, 6s, 8s
}
}
throw new Error(`Failed to fetch ${url} after ${maxRetries} retries`)
}

const [response1, response2, response3, response4, response5, response6, response7] = await Promise.all([
fetchWithRetry(`${deployUrl}/.netlify/functions/func-1`).then((res) => res.text()),
fetchWithRetry(`${deployUrl}/.netlify/functions/func-2`).then((res) => res.text()),
Expand Down Expand Up @@ -1033,7 +1021,7 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
},
true,
)) as unknown as Deploy
const response = await fetch(`${deployUrl}/.netlify/functions/func-1`).then((res) => res.text())
const response = await fetchWithRetry(`${deployUrl}/.netlify/functions/func-1`).then((res) => res.text())

t.expect(response).toEqual('Internal')
})
Expand Down Expand Up @@ -1176,7 +1164,9 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
},
true,
)) as unknown as Deploy
const response = await fetch(`${deployUrl}/.netlify/functions/bundled-function-1`).then((res) => res.text())
const response = await fetchWithRetry(`${deployUrl}/.netlify/functions/bundled-function-1`).then((res) =>
res.text(),
)
expect(response).toEqual('Pre-bundled')
})
})
Expand Down Expand Up @@ -1236,7 +1226,9 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
true,
)) as unknown as Deploy

const response = await fetch(`${deployUrl}/.netlify/functions/bundled-function-1`).then((res) => res.text())
const response = await fetchWithRetry(`${deployUrl}/.netlify/functions/bundled-function-1`).then((res) =>
res.text(),
)
t.expect(response).toEqual('Bundled at deployment')
})
})
Expand Down Expand Up @@ -1297,7 +1289,9 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
true,
)) as unknown as { deploy_url: string }

const response = await fetch(`${deployUrl}/.netlify/functions/bundled-function-1`).then((res) => res.text())
const response = await fetchWithRetry(`${deployUrl}/.netlify/functions/bundled-function-1`).then((res) =>
res.text(),
)
t.expect(response).toEqual('Bundled at deployment')
})
})
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/commands/dev/v2-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe.runIf(gte(version, '20.12.2')).concurrent('v2 api', async () => {
expect(thirdChunk.done).toBeTruthy()
})

test<FixtureTestContext>('receives context', async ({ devServer, expect }) => {
test<FixtureTestContext>('receives context', { retry: 3 }, async ({ devServer, expect }) => {
const response = await fetch(`http://localhost:${devServer!.port}/.netlify/functions/context`, {
headers: {
Cookie: 'foo=bar;',
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/utils/fetch-with-retry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { pause } from './pause.js'

export const fetchWithRetry = async (url: string, options?: RequestInit, maxRetries = 5): Promise<Response> => {
for (let i = 0; i < maxRetries; i++) {
try {
const response = await fetch(url, options)
if (response.status !== 404) {
return response
}
if (i < maxRetries - 1) {
await pause(2000 * (i + 1))
}
} catch (error) {
if (i === maxRetries - 1) throw error
await pause(2000 * (i + 1))
}
}
return fetch(url, options)
}
Loading