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

Warn when unlisten called multiple times #437

Closed
wants to merge 1 commit into from

Conversation

aij
Copy link

@aij aij commented Feb 24, 2017

Per discussion on #436 , emit a warning while preserving existing behavior.

@mjackson
Copy link
Member

Is one of our tests calling unlisten more than once? Can you tell which one it is and fix it?

@mjackson
Copy link
Member

A warning without a fix for the bad behavior is just going to annoy people.

@aij
Copy link
Author

aij commented Feb 24, 2017

That was my thought as well, which was why I included a fix to the tests in the first PR... Did you want the same fix or or would you prefer something different?

The problem is in execSteps.js, execNextStep() calls cleanup() twice for the last step, first inside the try and then again inside the catch.

@aij
Copy link
Author

aij commented Feb 25, 2017

And I guess the followup question is: Once the tests no longer leave the history object in an inconsistent state, should they keep using the same one instead of throwing it out and creating a new one as they currently do? (I think there is still some merit to creating a new one each time, in that it avoids state from earlier tests from potentially breaking later tests.)

@mjackson
Copy link
Member

The problem is in execSteps.js, execNextStep() calls cleanup() twice for the last step, first inside the try and then again inside the catch.

Good catch, thank you.

I didn't like the "fix" in the first PR because it was just setting unlisten to a no-op instead of fixing the fact that it was being called twice.

should they keep using the same one instead of throwing it out and creating a new one as they currently do?

No, I like creating a new object each time. It helps to know we're starting with fresh state in every test.

@mjackson mjackson closed this in c97ec68 Feb 26, 2017
@aij
Copy link
Author

aij commented Feb 27, 2017

Could we still include the warning though? I'm more worried about this happening in real code rather than just in the tests.

Also, sorry I may have misunderstood what you didn't like earlier. I thought you were opposed to making the unlisten function idempotent in case anyone might be relying on the old behavior. I hadn't realized updating the function pointer in the cleanup function was (also?) what you found objectionable.

@mjackson
Copy link
Member

Instead of including a warning, how about we just make sure we don't decrement the listenerCount if it's called multiple times? Ideally, it wouldn't matter if they did call unlisten many times. We just don't want it to affect our internal state.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
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