-
Notifications
You must be signed in to change notification settings - Fork 45.6k
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
Adding more schedule tests #12858
Adding more schedule tests #12858
Conversation
3b2c738
to
c5fbdc4
Compare
Edit: I rebased and now this only has the changes which need reviewed. If you look at the second commit, that's my changes. I want a better API for simulating the change in time during a frame, will work on that in a follow-up diff. |
**what is the change?:** Test coverage checking that callbacks are called when they time out. This test surfaced a bug and this commit includes the fix. I want to refine this approach, but basically we can simulate time outs by controlling the return value of 'now()' and the argument passed to the rAF callback. Next we will write a browser fixture to further test this against real browser APIs. **why make this change?:** Better tests will keep this module working smoothly while we continue refactoring and improving it. **test plan:** Run the new tests, see that it fails without the bug fix.
c5fbdc4
to
fc5a0ea
Compare
runRAFCallbacks(); // runs rAF callback | ||
// push time ahead a bit so that we have no idle time | ||
startOfLatestFrame += 16; | ||
drainPostMessageQueue(); // runs postMessage callback, idleTick |
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 plan to improve the API for writing these tests; instead of drainPostMessageQueue
and runRAFCallbacks
it should be more generic and descriptive, like so:
const shorterTimeout = 2;
const longerTimeout = 100;
scheduleWork(callbackA);
scheduleWork(callbackB, {timeout: longerTimeout});
scheduleWork(callbackC, {timeout: shorterTimeout});
// generic API for advancing a frame and configuring how much idle time there will be
advanceByOneFrame({timeRemaining: -1 * (longerTimeout * 2)});
// idle time was negative, so there was none and we passed the timeout threshhold for the shorterTimeout
expect(callbackLog).toEqual(['C']);
// ... etc.
Going to continue working on top of this soon, hopefully any issues can be done in a follow-up PR since this is just adding tests. 😇 |
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 like your proposal to make the tests a bit more semantic
Tests and fixes for 'timing out' behavior
what is the change?:
Test coverage checking that callbacks are called when they time out.
This test surfaced a bug and this commit includes the fix.
I want to refine this approach, but basically we can simulate time outs
by controlling the return value of 'now()' and the argument passed to
the rAF callback.
Next we will write a browser fixture to further test this against real
browser APIs.
why make this change?:
Better tests will keep this module working smoothly while we continue
refactoring and improving it.
test plan:
Run the new tests, see that it fails without the bug fix.