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

[cloud_firestore] Improve reliability of includeMetadataChanges integration test #32

Merged
merged 3 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <flutter-dev@googlegroups.com>
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