Commit 04fa775
authored
Extend createServicePolicy to support live network status (#7164)
## 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?
-->
In a future commit we will introduce changes to `network-controller` so
that it will keep track of the status of each network as requests are
made. These updates to `createServicePolicy` assist with that. See the
changelog for more.
Besides this, the tests for `createServicePolicy` have been refactored
slightly so that they are easier to maintain in the future.
## 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
-->
Progresses https://consensyssoftware.atlassian.net/browse/WPC-99.
You can see how these changes will be used in the next PR:
#7166
## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
- [x] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds `getCircuitState`, `onAvailable`, and `reset` to `ServicePolicy`,
exports Cockatiel types, and updates logic/tests to support availability
tracking and circuit state introspection.
>
> - **controller-utils**:
> - **ServicePolicy API**:
> - Add `getCircuitState()` to expose underlying circuit state.
> - Add `onAvailable` event for first success and post-recovery success.
> - Add `reset()` to close the circuit and reset breaker counters.
> - **Behavior/Internals**:
> - Track availability status and emit `onAvailable`/`onDegraded`
appropriately.
> - Update `onBreak` to mark unavailable; wire `ConsecutiveBreaker` for
reset.
> - **Exports**:
> - Export `CockatielEventEmitter` and `CockatielFailureReason`;
re-export via `index`.
> - **Tests**:
> - Expand/refactor tests to cover `onAvailable`, `getCircuitState`,
`reset`, and timing cases; update export snapshot.
> - **Docs**:
> - Update `CHANGELOG.md` with new methods and exports.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
e597d0b. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 775ce93 commit 04fa775
File tree
5 files changed
+1935
-1079
lines changed- packages/controller-utils
- src
5 files changed
+1935
-1079
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
10 | 21 | | |
11 | 22 | | |
12 | 23 | | |
| |||
0 commit comments