Skip to content

Fix waitsForCount in EventAccumulator (tests) #1378

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

Merged
merged 1 commit into from
Nov 10, 2018

Conversation

jsayol
Copy link
Contributor

@jsayol jsayol commented Nov 10, 2018

The waitsForCount(count) helper function for the tests of the realtime database returns an EventAccumulator that is supposed to wait for count events to happen before resolving its Promise.

The current implementation, though, always resolves its Promise after the very first event no matter how many were specified. This could lead to tests behaving erroneously.

A quick demo to verify this incorrect behavior:

const ea = EventAccumulatorFactory.waitsForCount(3);

setTimeout(() => {
  console.log('1');
  ea.addEvent();
}, 100);

setTimeout(() => {
  console.log('2');
  ea.addEvent();
}, 200);

setTimeout(() => {
  console.log('3');
  ea.addEvent();
}, 300);

ea.promise.then(() => console.log('done'));

This outputs the following:

1
done
2
3

When it should output this:

1
2
3
done

This PR fixes this. I've rerun all the tests in the database package after the change and they all keep passing, so I guess we got lucky ¯\_(ツ)_/¯

@schmidt-sebastian
Copy link
Contributor

Thanks for this contribution (and for catching this issue!)! Looks good to me.

@schmidt-sebastian schmidt-sebastian merged commit 8375f67 into firebase:master Nov 10, 2018
@jsayol jsayol deleted the fix-waitsforcount branch November 10, 2018 02:09
@firebase firebase locked and limited conversation to collaborators Oct 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants