Skip to content
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

Merged
merged 1 commit into from
May 22, 2018
Merged

Conversation

flarnie
Copy link
Contributor

@flarnie flarnie commented May 18, 2018

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.

@flarnie flarnie requested a review from acdlite May 18, 2018 17:06
@flarnie flarnie changed the title WIP/RFC: Adding more schedule tests Adding more schedule tests May 18, 2018
@flarnie
Copy link
Contributor Author

flarnie commented May 18, 2018

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.
runRAFCallbacks(); // runs rAF callback
// push time ahead a bit so that we have no idle time
startOfLatestFrame += 16;
drainPostMessageQueue(); // runs postMessage callback, idleTick
Copy link
Contributor Author

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.

@flarnie
Copy link
Contributor Author

flarnie commented May 21, 2018

pingingtrick

@flarnie
Copy link
Contributor Author

flarnie commented May 21, 2018

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

Copy link
Collaborator

@acdlite acdlite left a 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

@flarnie
Copy link
Contributor Author

flarnie commented May 22, 2018

thanks_pikachu

@flarnie flarnie merged commit 33289b5 into facebook:master May 22, 2018
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.

None yet

3 participants