Skip to content
Open
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
17 changes: 14 additions & 3 deletions packages/blobs/src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { env, version as nodeVersion } from 'node:process'
import { MockFetch } from '@netlify/test-utils'
import { base64Decode } from '@netlify/runtime-utils'
import semver from 'semver'
import { describe, test, expect, beforeAll, afterEach } from 'vitest'
import { describe, test, expect, beforeAll, afterEach, vi } from 'vitest'

import { base64Encode, streamToString } from '../test/util.js'

Expand All @@ -30,6 +30,7 @@ beforeAll(async () => {
afterEach(() => {
delete env.NETLIFY_BLOBS_CONTEXT
delete globalThis.netlifyBlobsContext
vi.useRealTimers()
})

const deployID = '6527dfab35be400008332a1d'
Expand Down Expand Up @@ -1145,6 +1146,8 @@ describe('set', () => {
})

test('Retries failed operations', async () => {
vi.useFakeTimers()

const mockStore = new MockFetch()
.put({
headers: { authorization: `Bearer ${apiToken}` },
Expand Down Expand Up @@ -1191,7 +1194,10 @@ describe('set', () => {
siteID,
})

await blobs.set(key, value)
const operation = blobs.set(key, value)

await vi.runAllTimersAsync()
await operation

expect(mockStore.fulfilled).toBeTruthy()
})
Expand Down Expand Up @@ -1252,6 +1258,8 @@ describe('set', () => {
})

test('Retries failed operations', async () => {
vi.useFakeTimers()

const mockStore = new MockFetch()
.put({
body: value,
Expand Down Expand Up @@ -1286,7 +1294,10 @@ describe('set', () => {
siteID,
})

await blobs.set(key, value)
const operation = blobs.set(key, value)

await vi.runAllTimersAsync()
await operation

expect(mockStore.fulfilled).toBeTruthy()
})
Expand Down
13 changes: 13 additions & 0 deletions packages/blobs/src/retry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { afterEach, expect, test, vi } from 'vitest'

afterEach(() => vi.unstubAllGlobals())

test('does not access the process environment during import', async () => {
vi.stubGlobal('process', {
get env() {
throw new Error('Environment access is not allowed')
},
})

await expect(import('./retry.ts')).resolves.toHaveProperty('fetchAndRetry')
})
4 changes: 1 addition & 3 deletions packages/blobs/src/retry.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { getEnvironment } from '@netlify/runtime-utils'

import type { Fetcher } from './types.ts'

const DEFAULT_RETRY_DELAY = getEnvironment().get('NODE_ENV') === 'test' ? 1 : 5000
const DEFAULT_RETRY_DELAY = 5000
const MIN_RETRY_DELAY = 1000
const MAX_RETRY = 5
const RATE_LIMIT_HEADER = 'X-RateLimit-Reset'
Expand Down
Loading