Skip to content

Commit ae9d9a0

Browse files
committed
fix: prettier formatting
1 parent 1dc177b commit ae9d9a0

File tree

1 file changed

+64
-68
lines changed

1 file changed

+64
-68
lines changed

packages/browser/playwright/mocked/retry-queue.spec.ts

Lines changed: 64 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,80 +8,76 @@ const startOptions = {
88
}
99

1010
test.describe('retry queue', () => {
11-
test(
12-
'retries failed capture requests and stops after success',
13-
async ({ page, context }) => {
14-
const captureRequests: Request[] = []
15-
let errorResponseCount = 0
16-
const maxErrorResponses = 3
17-
let successSeen = false
18-
19-
// Mock the capture endpoint to fail initially, then succeed
20-
await context.route('**/e/**', async (route) => {
21-
const request = route.request()
22-
captureRequests.push(request)
23-
24-
if (errorResponseCount < maxErrorResponses) {
25-
errorResponseCount++
26-
await route.fulfill({
27-
status: 500,
28-
contentType: 'text/plain',
29-
body: 'Internal Server Error',
30-
})
31-
} else {
32-
successSeen = true
33-
await route.fulfill({
34-
status: 200,
35-
contentType: 'application/json',
36-
body: JSON.stringify({ status: 'ok' }),
37-
})
38-
}
39-
})
11+
test('retries failed capture requests and stops after success', async ({ page, context }) => {
12+
const captureRequests: Request[] = []
13+
let errorResponseCount = 0
14+
const maxErrorResponses = 3
15+
let successSeen = false
4016

41-
// Initialize PostHog without pageview to avoid extra requests
42-
await start({ ...startOptions, options: { capture_pageview: false } }, page, context)
17+
// Mock the capture endpoint to fail initially, then succeed
18+
await context.route('**/e/**', async (route) => {
19+
const request = route.request()
20+
captureRequests.push(request)
4321

44-
// Capture a custom event which will initially fail
45-
await page.evaluate(() => {
46-
window.posthog.capture('test-retry-event', { test: 'data' })
47-
})
22+
if (errorResponseCount < maxErrorResponses) {
23+
errorResponseCount++
24+
await route.fulfill({
25+
status: 500,
26+
contentType: 'text/plain',
27+
body: 'Internal Server Error',
28+
})
29+
} else {
30+
successSeen = true
31+
await route.fulfill({
32+
status: 200,
33+
contentType: 'application/json',
34+
body: JSON.stringify({ status: 'ok' }),
35+
})
36+
}
37+
})
4838

49-
// Wait until we see the successful response (4th request)
50-
await expect(async () => {
51-
expect(successSeen).toBe(true)
52-
}).toPass({ timeout: 50000 })
39+
// Initialize PostHog without pageview to avoid extra requests
40+
await start({ ...startOptions, options: { capture_pageview: false } }, page, context)
5341

54-
// Check that we got multiple requests
55-
expect(captureRequests.length).toBeGreaterThanOrEqual(3)
42+
// Capture a custom event which will initially fail
43+
await page.evaluate(() => {
44+
window.posthog.capture('test-retry-event', { test: 'data' })
45+
})
5646

57-
// Verify the first request had no retry_count
58-
const firstRequest = captureRequests[0]
59-
expect(firstRequest.url()).not.toContain('retry_count')
47+
// Wait until we see the successful response (4th request)
48+
await expect(async () => {
49+
expect(successSeen).toBe(true)
50+
}).toPass({ timeout: 50000 })
6051

61-
// Verify retry_count increments
62-
const retryCountMatches = captureRequests
63-
.map((req) => {
64-
const match = req.url().match(/retry_count=(\d+)/)
65-
return match ? parseInt(match[1]) : null
66-
})
67-
.filter((count) => count !== null)
68-
69-
// Should see incrementing retry counts
70-
expect(retryCountMatches.length).toBeGreaterThanOrEqual(2)
71-
expect(retryCountMatches).toContain(1)
72-
expect(retryCountMatches).toContain(2)
73-
// Verify counts are actually incrementing (not stuck at 1)
74-
const uniqueCounts = Array.from(new Set(retryCountMatches))
75-
expect(uniqueCounts.length).toBeGreaterThan(1)
76-
77-
// After success, record the count and verify no more requests arrive
78-
const requestCountAfterSuccess = captureRequests.length
79-
await expect(async () => {
80-
expect(captureRequests.length).toBe(requestCountAfterSuccess)
81-
}).toPass({ timeout: 5000 })
82-
},
83-
90000
84-
)
52+
// Check that we got multiple requests
53+
expect(captureRequests.length).toBeGreaterThanOrEqual(3)
54+
55+
// Verify the first request had no retry_count
56+
const firstRequest = captureRequests[0]
57+
expect(firstRequest.url()).not.toContain('retry_count')
58+
59+
// Verify retry_count increments
60+
const retryCountMatches = captureRequests
61+
.map((req) => {
62+
const match = req.url().match(/retry_count=(\d+)/)
63+
return match ? parseInt(match[1]) : null
64+
})
65+
.filter((count) => count !== null)
66+
67+
// Should see incrementing retry counts
68+
expect(retryCountMatches.length).toBeGreaterThanOrEqual(2)
69+
expect(retryCountMatches).toContain(1)
70+
expect(retryCountMatches).toContain(2)
71+
// Verify counts are actually incrementing (not stuck at 1)
72+
const uniqueCounts = Array.from(new Set(retryCountMatches))
73+
expect(uniqueCounts.length).toBeGreaterThan(1)
74+
75+
// After success, record the count and verify no more requests arrive
76+
const requestCountAfterSuccess = captureRequests.length
77+
await expect(async () => {
78+
expect(captureRequests.length).toBe(requestCountAfterSuccess)
79+
}).toPass({ timeout: 5000 })
80+
}, 90000)
8581

8682
test('stops retrying after 10 attempts', async ({ page, context }) => {
8783
const captureRequests: Request[] = []

0 commit comments

Comments
 (0)