fix metrics test#916
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughReplaces direct metrics assertions in an end-to-end test with a retry-based approach using Result.retry to wait for eventual consistency, adjusts assertions to use result.data.body fields, and integrates retry outcome into final checks and helper invocation. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Tester
participant Test as E2E Test
participant Retry as Result.retry
participant API as Internal Metrics API
Tester->>Test: Run internal-metrics test
Test->>API: Capture baseline metrics
alt Retry until metrics match baseline
Test->>Retry: Invoke with fetch+compare
loop Attempts with backoff
Retry->>API: Fetch metrics
API-->>Retry: Response
Retry->>Retry: Compare to baseline
end
Retry-->>Test: Success (data.body)
else Error after retries
Retry-->>Test: Error
Test->>Test: Assert last metrics equal to baseline
Test-->>Tester: Throw error
end
Test->>Test: Assert totals/recent/daily/by-country on result.data.body
Test->>Test: ensureAnonymousUsersAreStillExcluded(result.data)
Test-->>Tester: Complete
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests
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.
Review by RecurseML
🔍 Review performed on 3fe82b6..99fe457
| Severity | Location | Issue | Delete |
|---|---|---|---|
| apps/e2e/tests/backend/endpoints/api/v1/internal-metrics.test.ts:130 | Missing runAsynchronously wrapper for async operation |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/e2e/tests/backend/endpoints/api/v1/internal-metrics.test.ts (1)
139-140: Compare the response bodies for clearer diagnostics
Line 139 is comparingbeforeMetrics.bodyto the entireNiceResponsestored inresult.error, so the assertion will always fail even when the bodies match. Swapping toresult.error.bodykeeps the branch’s intent—surfacing the diff between the payloads—without a guaranteed mismatch.- expect(beforeMetrics.body).toEqual(result.error); + expect(beforeMetrics.body).toEqual(result.error.body);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/e2e/tests/backend/endpoints/api/v1/internal-metrics.test.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.test.{ts,tsx,js}
📄 CodeRabbit inference engine (AGENTS.md)
In tests, prefer .toMatchInlineSnapshot where possible; refer to snapshot-serializer.ts for snapshot formatting and handling of non-deterministic values
Files:
apps/e2e/tests/backend/endpoints/api/v1/internal-metrics.test.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Prefer ES6 Map over Record when representing key–value collections
Files:
apps/e2e/tests/backend/endpoints/api/v1/internal-metrics.test.ts
🧬 Code graph analysis (1)
apps/e2e/tests/backend/endpoints/api/v1/internal-metrics.test.ts (1)
apps/e2e/tests/backend/backend-helpers.ts (1)
niceBackendFetch(107-171)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: docker
- GitHub Check: docker
- GitHub Check: lint_and_build (latest)
- GitHub Check: restart-dev-and-test
- GitHub Check: all-good
- GitHub Check: build (22.x)
- GitHub Check: setup-tests
- GitHub Check: build (22.x)
- GitHub Check: Security Check
High-level PR Summary
This PR fixes a test in the internal metrics endpoint by replacing a simple wait timer with a more robust retry mechanism. Instead of waiting for a fixed 3000ms delay to allow for asynchronous event logging, the PR implements a
Result.retryapproach that attempts to fetch metrics up to 5 times with exponential backoff, only proceeding when the metrics response differs from the initial state. This change makes the test more reliable by ensuring proper test conditions are met before assertions are made rather than relying on an arbitrary timeout.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
apps/e2e/tests/backend/endpoints/api/v1/internal-metrics.test.tsSummary by CodeRabbit