-
Notifications
You must be signed in to change notification settings - Fork 943
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
Fix flaky test. #1511
Conversation
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); |
There was a problem hiding this comment.
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.
Er, actually I can fix this differently so that it both fixes the flakiness and is closer to the Android / iOS ports. One sec. |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Port flaky test fix from web. Port of firebase/firebase-js-sdk#1511
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.