Skip to content

Rewrite createServicePolicy tests#8666

Open
mcmire wants to merge 3 commits into
mainfrom
rewrite-create-service-policy-tests
Open

Rewrite createServicePolicy tests#8666
mcmire wants to merge 3 commits into
mainfrom
rewrite-create-service-policy-tests

Conversation

@mcmire

@mcmire mcmire commented May 1, 2026

Copy link
Copy Markdown
Contributor

Explanation

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

(Prerequisite for another PR that updates createServicePolicy)

Checklist

  • 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
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

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).

Reviewed by Cursor Bugbot for commit 1dd02ec. Bugbot is set up for automated code reviews on this repo. Configure here.

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.
@mcmire

mcmire commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Adding no-changelog because this PR only contains changes to tests.


expect(mockService).toHaveBeenCalledTimes(1);
});
describe('execute', () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best to view this file on its own rather than going through the diff.

@mcmire mcmire marked this pull request as ready for review May 1, 2026 17:38
@mcmire mcmire requested a review from a team as a code owner May 1, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant