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

Two-subscription test that actually works and fix. #694

Closed
wants to merge 2 commits into from

Conversation

tmeasday
Copy link
Contributor

@tmeasday tmeasday commented Sep 22, 2016

Sigh. The previous test, despite my best efforts, wasn't actually working properly. I think this one does.

The bug is that if you subscribe twice to a query and unsubscribe from one, it also unsubscribes the other.

@@ -601,7 +601,13 @@ describe('QueryManager', () => {
handle.refetch();
} else if (subTwoCount === 2) {
assert.deepEqual(result.data, data2);
done();
setTimeout(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not clear which subscriber will trigger first so this timeout is necessary.

@tmeasday
Copy link
Contributor Author

Oh, you know what, if you stop one subscription things will break as well: https://github.com/apollostack/apollo-client/blob/master/src/ObservableQuery.ts#L65-L66

Will add to this PR

@tmeasday
Copy link
Contributor Author

tmeasday commented Sep 26, 2016

Ok, I realised this was only half the story, and in fact you can't unsubscribe to a single sub either.

I'd like to fix it but the code for tracking this stuff is a complete mess:

  • queryManager.addObservableQuery
  • queryManager.addQuerySubscription
  • queryManager.startQuery

Are all in fact variants on the same thing. And the listener is created in QueryManager.ts yet the unsub function is created in ObservableQuery.ts. Uggh.

I need a consult.

@tmeasday
Copy link
Contributor Author

Probably related: #703

@tmeasday
Copy link
Contributor Author

@helfer I'm not sure exactly when I am going to look at this, (maybe next week?) so if you want to merge of it apart from the failing test or something, that might make sense.

At the moment I think you can subscribe twice OK now, you just can't subscribe twice then unsubscribe once right now.

@helfer
Copy link
Contributor

helfer commented Sep 29, 2016

@tmeasday yeah, I think it might make more sense for us to clean up the code and fix it during the upcoming refactoring. I'm trying to merge everything I can today so we can refactor without worrying too much.

@tmeasday
Copy link
Contributor Author

Ok, well maybe instead we should just cherry pick the tests across into the refactoring. Up to you.

@helfer
Copy link
Contributor

helfer commented Sep 29, 2016

Yeah, +1 for the tests. Although right now they're failing since I merged that other PR :(

@glasser
Copy link
Member

glasser commented Oct 13, 2016

Also, calling result() on an ObservableQuery can kill its subscription due to this.

And thus calling setVariables or setOptions can also unsubscribe (since in some cases they call result).

glasser added a commit that referenced this pull request Oct 13, 2016
react-apollo calls setOptions and ignores the return value. Sometimes
setOptions calls this.result() which subscribes and unsubscribes to the
query, but this actually unsubscribes the main subscription too, which
is bad.  We should fix the underlying bug but until then react-apollo
can call _setOptionsNoResult instead.
tmeasday added a commit to apollographql/react-apollo that referenced this pull request Oct 14, 2016
@stubailo stubailo modified the milestone: Release 0.5 Oct 16, 2016
@stubailo stubailo force-pushed the cannot-subscribe-two-times-version-2 branch from e1799b0 to 3f5ab67 Compare October 16, 2016 01:40
@stubailo
Copy link
Contributor

Fixed in #791

@stubailo stubailo closed this Oct 17, 2016
@stubailo stubailo deleted the cannot-subscribe-two-times-version-2 branch January 5, 2017 06:21
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2023
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.

5 participants