Improve e2e test performance with polling and parallelization#3415
Improve e2e test performance with polling and parallelization#3415steven-tey merged 2 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughTest execution patterns shift from sequential to parallel HTTP requests using Changes
Sequence DiagramsequenceDiagram
participant Test as Test Suite
participant API as API Endpoints
participant Verify as verifyCommission()
Test->>Test: Issue multiple POST /track/sale<br/>(in parallel via Promise.all)
Note over Test,API: Old behavior (sequential)
Test->>API: POST /track/sale (wait)
API-->>Test: Response
Test->>API: POST /track/sale (wait)
API-->>Test: Response
Note over Test,Verify: New behavior (polling)
Test->>Verify: verifyCommission(invoiceId)
loop Every 5s until 30s timeout
Verify->>API: GET /customers
API-->>Verify: Customer list
Verify->>API: GET /commissions
API-->>Verify: Commission data
alt Status 200 & exactly one commission
Verify->>Verify: Verify invoiceId,<br/>customerId,<br/>amount, earnings
Verify-->>Test: ✓ Success
else Not ready yet
Note over Verify: Wait 5s, retry
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/web/tests/tracks/track-sale.test.ts (1)
42-78:⚠️ Potential issue | 🟠 MajorConcurrent suite makes the idempotency test unreliable.
describe.concurrentruns tests in parallel usingPromise.all. Both tests currently use the same sharedsale.invoiceId, so when they execute concurrently, the second POST request for "already processed invoiceId" is not guaranteed to hit an already-processed state—both requests may hit the server simultaneously. This makes the idempotency test ineffective.Fix this by making the idempotency test self-contained: have a single test post the same invoiceId twice sequentially within that test, then verify the responses match.
✅ Suggested fix (self-contained idempotency test)
- test("track a sale with an invoiceId that is already processed (should return the same response as before) ", async () => { - const response = await http.post<TrackSaleResponse>({ - path: "/track/sale", - body: { - ...sale, - customerExternalId: E2E_CUSTOMER_EXTERNAL_ID, - invoiceId: sale.invoiceId, - }, - }); - - // should return the same response since it's idempotent - expectValidSaleResponse(response, sale); - }); + test("track a sale with an invoiceId that is already processed (should return the same response as before) ", async () => { + const invoiceId = `INV_${randomId()}`; + const salePayload = { + ...sale, + customerExternalId: E2E_CUSTOMER_EXTERNAL_ID, + invoiceId, + }; + + const first = await http.post<TrackSaleResponse>({ + path: "/track/sale", + body: salePayload, + }); + const second = await http.post<TrackSaleResponse>({ + path: "/track/sale", + body: salePayload, + }); + + expectValidSaleResponse(first, salePayload); + expectValidSaleResponse(second, salePayload); + });
🤖 Fix all issues with AI agents
In `@apps/web/tests/tracks/track-sale.test.ts`:
- Around line 115-127: The test currently uses optional chaining plus non-null
assertion (response1.data.sale?.amount! / response2.data.sale?.amount!) which
violates noNonNullAssertedOptionalChain; instead guard that sale exists first
(e.g., assert/throw/expect that response1.data.sale and response2.data.sale are
non-null) and then access .amount directly when calling verifyCommission; update
the calls to verifyCommission (referencing verifyCommission, response1,
response2, expectedAmount) to remove the ?. and ! by first checking
responseX.data.sale and then using responseX.data.sale.amount.
Summary by CodeRabbit