diff --git a/packages/cloud_firestore/CHANGELOG.md b/packages/cloud_firestore/CHANGELOG.md index 2dee1a9bb4ff..82886887ba33 100644 --- a/packages/cloud_firestore/CHANGELOG.md +++ b/packages/cloud_firestore/CHANGELOG.md @@ -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. diff --git a/packages/cloud_firestore/example/test_driver/cloud_firestore.dart b/packages/cloud_firestore/example/test_driver/cloud_firestore.dart index 2c984f7d6985..12460b7ad07f 100644 --- a/packages/cloud_firestore/example/test_driver/cloud_firestore.dart +++ b/packages/cloud_firestore/example/test_driver/cloud_firestore.dart @@ -110,28 +110,29 @@ void main() { final DocumentReference ref = firestore.collection('messages').document(); final Stream 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 snapshotsWithMetadataChanges = ref.snapshots(includeMetadataChanges: true).take(3); ref.setData({'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 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(); }); diff --git a/packages/cloud_firestore/pubspec.yaml b/packages/cloud_firestore/pubspec.yaml index 69d41a2dea6d..b3a2adc19547 100755 --- a/packages/cloud_firestore/pubspec.yaml +++ b/packages/cloud_firestore/pubspec.yaml @@ -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 homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/cloud_firestore -version: 0.12.9+1 +version: 0.12.9+2 flutter: plugin: