-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(usePersistedStateReducer.test): Fix flaky test of push tab retry #2191
Conversation
Coverage of commit
|
@@ -48,32 +48,31 @@ const usePersistedStateReducer = (): [State, Dispatch] => { | |||
|
|||
const { routeTabsToPush, routeTabsPushInProgress } = state | |||
|
|||
const [routeTabsPushRetriesLeft, setRouteTabsPushRetriesLeft] = | |||
useState(routeTabsPushRetries) | |||
const routeTabsPushRetriesLeft = useRef(routeTabsPushRetries) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: I'm wondering if it would even be possible to simply use a local variable in usePersistedStateReducer
rather than a ref
, though I haven't thought it all the way through yet and my naive attempt at doing it locally isn't working. This logic is really hard to reason about and I'm hoping there's some way to simplify it a bit further but it might not be possible while fully obeying all of the rules of hooks and everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't been able to get it working using a local variable either - doing some logging in the useEffect
, it seems that as a local variable, the value never is decremented. My hunch is that it has do with the local variable being reset when the state returned by useReducer
changes and forces a re-render, whereas useRef
will persist across re-renders
…before assertions
…instead of state Prevents possible race conditions with between asynchronously updating the remaining retries count state & updating the tab state from dispatching actions
656984e
to
e039e78
Compare
Coverage of commit
|
ticket: https://app.asana.com/0/1148853526253437/1204432665252080/f
I was unable to reproduce the flaky test's failure across 1000+ runs, so it has been tricky confirming if these two changes address the root of the problem, but it seems to me that both of these changes would reduce the likeliness of flaky behavior.
act
- this allows us to remove the use of intermediate state variables &waitFor
in the tests by waiting until all side effects are resolved. Act is still a bit mysterious to me, but I referenced this explanation linked from the rtl docs for this approach.useRef
instead ofuseState
in theusePersistedStateReducer
so that updates torouteTabsPushRetriesLeft
are synchronous. This prevents a possible race conditions between updatingrouteTabsPushRetriesLeft
and dispatching the retry action.