Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Clear out scheduler on MockedProvider unmount #2151

Merged
merged 3 commits into from
Jul 3, 2018

Conversation

danilobuerger
Copy link
Contributor

Currently using pollInterval leads to the following jest error message while testing:

Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests.

This is because when stopPolling is called, the actual polling timer is not getting deleted right away but after the interval completes. So we have to wait for one whole interval before jest can exist. See fetchQueriesOnInterval in the scheduler for the implementation details.

This PR assumes that MockedProvider is only ever run with the intention that when it is unmounted every client op should also stop.

When MockedProvider is going to be unmounted, this PR adds the functionality to loop over all existing registered queries in the scheduler and clearing their intervals immediately.

Copy link
Contributor

@rosskevin rosskevin left a comment

Choose a reason for hiding this comment

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

Looks good, I was going to add better types but wanted to check PRs first. Thanks! If you address the name really quick I think this is good to merge.

export * from './test-links';

export class MockedProvider extends React.Component<any, any> {
static defaultProps = {
interface IProps {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer export interface MockedProviderProps - both for reuse/composition and better IDE suggestions

defaultOptions?: DefaultOptions;
}

interface IState {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer export interface MockedProviderState - consistency with above.

Partially verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
@danilobuerger
Copy link
Contributor Author

@rosskevin amended, tests are passing

@rosskevin rosskevin changed the title Polling while testing leads to zombies Clear out scheduler on MockedProvider unmount Jul 3, 2018
@rosskevin rosskevin merged commit b346e3e into apollographql:master Jul 3, 2018
danilobuerger added a commit to danilobuerger/react-apollo that referenced this pull request Aug 2, 2018
hwillson pushed a commit that referenced this pull request Aug 17, 2018
@danilobuerger danilobuerger deleted the scheduler branch January 19, 2019 12:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants