Skip to content

Fix flaky test. #1511

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
Feb 1, 2019
Merged

Conversation

mikelehen
Copy link
Contributor

The "can return previous value through consecutive updates" test was flaky
because it did two consecutive server timestamp writes to the same field and
expected 2 local events. But if you do both writes within 1ms then the
snapshots will be indistinguishable (the estimated value for the server
timestamps will be the same) and so only 1 event will be raised. I added an
additional change to the second write to guarantee it triggers an event.

While looking at the test, I also noticed it was slightly broken / incomplete.
There was an incorrect line attempting to disable the network and the test was
missing the remaining code to re-enable the network and verify the behavior. I
fixed that as well.

The "can return previous value through consecutive updates" test was flaky
because it did two consecutive server timestamp writes to the same field and
expected 2 local events. But if you do both writes within 1ms then the
snapshots will be indistinguishable (the estimated value for the server
timestamps will be the same) and so only 1 event will be raised. I added an
additional change to the second write to guarantee it triggers an event.

While looking at the test, I also noticed it was slightly broken / incomplete.
There was an incorrect line attempting to disable the network and the test was
missing the remaining code to re-enable the network and verify the behavior.  I
fixed that as well.
.then(() => {
// We set up two consecutive writes with server timestamps.
docRef.update('a', FieldValue.serverTimestamp());
docRef.update('a', FieldValue.serverTimestamp());
// include b=1 to ensure there's a change resulting in a new snapshot.
docRef.update('a', FieldValue.serverTimestamp(), 'b', 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the actual fix. The rest is just making the test actually disable/re-enable the network and match the other ports.

@mikelehen mikelehen removed the request for review from gsoltis February 1, 2019 00:18
@mikelehen
Copy link
Contributor Author

Er, actually I can fix this differently so that it both fixes the flakiness and is closer to the Android / iOS ports. One sec.

@mikelehen
Copy link
Contributor Author

Eh, nevermind. Android is flaky too though it's probably less likely (because it does more work between the subsequent writes), but there could still technically be a timing issue.

@mikelehen mikelehen requested a review from gsoltis February 1, 2019 00:25
mikelehen pushed a commit to firebase/firebase-android-sdk that referenced this pull request Feb 1, 2019
mikelehen pushed a commit to firebase/firebase-ios-sdk that referenced this pull request Feb 1, 2019
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM

@mikelehen mikelehen merged commit 74d72ce into master Feb 1, 2019
@mikelehen mikelehen deleted the mikelehen/fix-flaky-server-timestamp-test branch February 1, 2019 16:56
mikelehen added a commit to firebase/firebase-android-sdk that referenced this pull request Feb 1, 2019
mikelehen added a commit to firebase/firebase-ios-sdk that referenced this pull request Feb 1, 2019
@firebase firebase locked and limited conversation to collaborators Oct 13, 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.

3 participants