Skip to content

Commit

Permalink
Merge pull request firebase#32 from collinjackson/flaky-test
Browse files Browse the repository at this point in the history
[cloud_firestore] Improve reliability of includeMetadataChanges integration test
  • Loading branch information
kroikie authored Aug 30, 2019
2 parents 14c3eab + 6697ccf commit d95af8f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
4 changes: 4 additions & 0 deletions packages/cloud_firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.12.9+2

* Fix flaky integration test for `includeMetadataChanges`.

## 0.12.9+1

* Update documentation to reflect new repository location.
Expand Down
27 changes: 14 additions & 13 deletions packages/cloud_firestore/example/test_driver/cloud_firestore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,29 @@ void main() {
final DocumentReference ref = firestore.collection('messages').document();
final Stream<DocumentSnapshot> snapshotWithoutMetadataChanges =
ref.snapshots(includeMetadataChanges: false).take(1);
// It should take either two or three snapshots to make a change when
// metadata is included, depending on whether `hasPendingWrites` and
// `isFromCache` update at the same time.
final Stream<DocumentSnapshot> snapshotsWithMetadataChanges =
ref.snapshots(includeMetadataChanges: true).take(3);

ref.setData(<String, dynamic>{'hello': 'world'});

final DocumentSnapshot snapshot =
await snapshotWithoutMetadataChanges.first;
DocumentSnapshot snapshot = await snapshotWithoutMetadataChanges.first;
expect(snapshot.metadata.hasPendingWrites, true);
expect(snapshot.metadata.isFromCache, true);
expect(snapshot.data['hello'], 'world');

final List<DocumentSnapshot> snapshots =
await snapshotsWithMetadataChanges.toList();
expect(snapshots[0].metadata.hasPendingWrites, true);
expect(snapshots[0].metadata.isFromCache, true);
expect(snapshots[0].data['hello'], 'world');
expect(snapshots[1].metadata.hasPendingWrites, true);
expect(snapshots[1].metadata.isFromCache, false);
expect(snapshots[1].data['hello'], 'world');
expect(snapshots[2].metadata.hasPendingWrites, false);
expect(snapshots[2].metadata.isFromCache, false);
expect(snapshots[2].data['hello'], 'world');
snapshot = await snapshotsWithMetadataChanges.take(1).first;
expect(snapshot.metadata.hasPendingWrites, true);
expect(snapshot.metadata.isFromCache, true);
expect(snapshot.data['hello'], 'world');

while (
snapshot.metadata.hasPendingWrites || snapshot.metadata.isFromCache) {
snapshot = await snapshotsWithMetadataChanges.take(1).first;
}
expect(snapshot.data['hello'], 'world');

await ref.delete();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cloud_firestore/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Cloud Firestore, a cloud-hosted, noSQL database
live synchronization and offline support on Android and iOS.
author: Flutter Team <[email protected]>
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/cloud_firestore
version: 0.12.9+1
version: 0.12.9+2

flutter:
plugin:
Expand Down

0 comments on commit d95af8f

Please sign in to comment.