Skip to content

Commit ded6a8a

Browse files
authored
Rewrite createServicePolicy tests (#8666)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> The tests for `createServicePolicy` are too exhaustive and are very painful to maintain. This commit rewrites the tests so that they focus on covering all lines instead of all code paths. Note that there are still some coverage issues with `createServicePolicy` because Istanbul treats the re-exported Cockatiel functions as untested. There doesn't seem to be a way around this short of switching to v8. We may consider doing that in another commit, but that is out of scope for now. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> (Prerequisite for another PR that updates `createServicePolicy`) ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Test-only refactor with no production code changes; risk is limited to possible gaps if the slimmer suite drops edge cases the old combinatorial tests covered. > > **Overview** > **Replaces the ~3.7k-line `createServicePolicy` test suite with a ~1k-line version** aimed at line coverage and easier maintenance instead of enumerating every combination of defaults and options. > > The new structure groups cases by behavior (`execute` success/degraded listeners, always-failing retries, circuit open vs closed, recovery after `circuitBreakDuration`, custom `retryFilterPolicy` / `isServiceFailure`, `httpStatus`, plus `getRemainingCircuitOpenDuration`, `getCircuitState`, and `reset`). Shared helpers **`createServicePolicyForTestingRetries`** (zero `ConstantBackoff`, auto-advance timers on retry, optional `breakAfterFirstExecution`) and **`createErroringService`** cut duplicated mock/timer boilerplate. > > **No changes to `create-service-policy` implementation** in this diff—only tests and imports (`ConstantBackoff`, `ServicePolicy`). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1dd02ec. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 9366b30 commit ded6a8a

1 file changed

Lines changed: 697 additions & 3434 deletions

File tree

0 commit comments

Comments
 (0)