Repository navigation
feat: retry idempotent requests on 429/502/503/504 in the shared fetch layer #21322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b5ede20
9b4364d
3d5ddd1
d767c7a
81ff8d1
72dd15c
cb10990
bbad486
5a36721
b2c44aa
7be2339
d7fb989
7b7f927
f74bb14
5f876db
78adba8
7e7cd76
d142bd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { CREDITS_ROUTE } from '@comfyorg/account-core/billing' | ||
| import type { | ||
| AccountCredential, | ||
| SessionSnapshot | ||
| } from '@comfyorg/account-core/session' | ||
| import { fromPartial } from '@total-typescript/shoehorn' | ||
| import type { User } from 'firebase/auth' | ||
| import { beforeEach, expect, it, vi } from 'vitest' | ||
|
|
||
| import { useWorkspaceAuthStore } from '@/platform/workspace/stores/workspaceAuthStore' | ||
|
Check warning on line 10 in src/platform/billing/sdk/billingSdkStore.retry.test.ts
|
||
| import { | ||
| stubAccountIdentityPort, | ||
|
Check warning on line 12 in src/platform/billing/sdk/billingSdkStore.retry.test.ts
|
||
| stubFirebaseAuthHarness | ||
| } from '@/utils/__tests__/stubAccountIdentityPort' | ||
|
|
||
| import { useBillingSdkStore } from './billingSdkStore' | ||
|
|
||
| vi.mock(import('@/platform/telemetry')) | ||
|
Check warning on line 18 in src/platform/billing/sdk/billingSdkStore.retry.test.ts
|
||
| vi.mock(import('@/composables/useFeatureFlags')) | ||
|
Check warning on line 19 in src/platform/billing/sdk/billingSdkStore.retry.test.ts
|
||
| vi.mock(import('@/platform/billing/composables/useBillingCapabilities')) | ||
| vi.mock(import('@/platform/settings/composables/useSettingsDialog')) | ||
|
Check warning on line 21 in src/platform/billing/sdk/billingSdkStore.retry.test.ts
|
||
| vi.mock(import('firebase/auth')) | ||
|
|
||
| const CREDENTIAL: AccountCredential = { | ||
| token: 'workspace-jwt', | ||
| expiresAt: Date.now() + 60 * 60 * 1000, | ||
| uid: 'uid-1', | ||
| workspace: { id: 'ws-1', name: 'Personal', type: 'personal' }, | ||
| role: 'owner', | ||
| permissions: ['workspace:read'] | ||
| } | ||
|
|
||
| const SNAPSHOT: SessionSnapshot<User> = { | ||
| phase: 'authenticated', | ||
| user: fromPartial<User>({ uid: 'uid-1' }), | ||
| session: CREDENTIAL | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| stubAccountIdentityPort() | ||
| stubFirebaseAuthHarness() | ||
| const session = useWorkspaceAuthStore().getUnifiedSessionClient() | ||
| vi.spyOn(session, 'getSnapshot').mockReturnValue(SNAPSHOT) | ||
| vi.spyOn(session, 'ensureFresh').mockResolvedValue({ | ||
| status: 'ok', | ||
| session: CREDENTIAL | ||
| }) | ||
| }) | ||
|
|
||
| it('reads the balance again after a 503 through the store wiring', async () => { | ||
| vi.useFakeTimers() | ||
| const answers = [ | ||
| new Response(null, { status: 503 }), | ||
| Response.json({ amount_micros: 1_000_000, currency: 'USD' }) | ||
| ] | ||
| vi.mocked(fetch).mockImplementation(async (input) => { | ||
| expect(String(input)).toContain(CREDITS_ROUTE) | ||
| const answer = answers.shift() | ||
| if (!answer) throw new Error('fetch called more times than scripted') | ||
| return answer | ||
| }) | ||
|
|
||
| const pending = useBillingSdkStore().readBalance() | ||
| await vi.advanceTimersByTimeAsync(10_000) | ||
|
|
||
| expect(await pending).toMatchObject({ | ||
| status: 'ok', | ||
| value: { amount_micros: 1_000_000 } | ||
| }) | ||
| expect(fetch).toHaveBeenCalledTimes(2) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.