From d0f7d6b3c053bbe0aabdd1993484997e4d740d99 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 25 Aug 2019 20:59:50 -0700 Subject: [PATCH 1/3] Improve reliability of includeMetadataChanges integration test --- packages/cloud_firestore/CHANGELOG.md | 4 ++++ .../example/test_driver/cloud_firestore.dart | 24 ++++++++++--------- packages/cloud_firestore/pubspec.yaml | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) 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..a0641b9160c7 100644 --- a/packages/cloud_firestore/example/test_driver/cloud_firestore.dart +++ b/packages/cloud_firestore/example/test_driver/cloud_firestore.dart @@ -110,28 +110,30 @@ 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 = snapshotsWithMetadataChanges.take(1).first; + expect(snapshots.metadata.hasPendingWrites, true); + expect(snapshots.metadata.isFromCache, true); + expect(snapshots.data['hello'], 'world'); + + while (snapshot.hasPendingWrites || snapshot.isFromCache) { + snapshot = snapshotsWithMetadataChanges.take(1).first; + } + expect(snapshots.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: From 34863f95318762522de584f3bb419f1b847c8e52 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 25 Aug 2019 21:05:13 -0700 Subject: [PATCH 2/3] test fixes --- .../example/test_driver/cloud_firestore.dart | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/cloud_firestore/example/test_driver/cloud_firestore.dart b/packages/cloud_firestore/example/test_driver/cloud_firestore.dart index a0641b9160c7..5cf8a33d31f0 100644 --- a/packages/cloud_firestore/example/test_driver/cloud_firestore.dart +++ b/packages/cloud_firestore/example/test_driver/cloud_firestore.dart @@ -123,17 +123,15 @@ void main() { expect(snapshot.metadata.isFromCache, true); expect(snapshot.data['hello'], 'world'); - final List snapshots = - await snapshotsWithMetadataChanges.toList(); - snapshot = snapshotsWithMetadataChanges.take(1).first; - expect(snapshots.metadata.hasPendingWrites, true); - expect(snapshots.metadata.isFromCache, true); - expect(snapshots.data['hello'], 'world'); - - while (snapshot.hasPendingWrites || snapshot.isFromCache) { - snapshot = snapshotsWithMetadataChanges.take(1).first; + 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(snapshots.data['hello'], 'world'); + expect(snapshot.data['hello'], 'world'); await ref.delete(); }); From 6697ccf8012bfc5e5495255fab2fccb3188dc447 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 25 Aug 2019 21:30:25 -0700 Subject: [PATCH 3/3] reformat --- .../cloud_firestore/example/test_driver/cloud_firestore.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/cloud_firestore/example/test_driver/cloud_firestore.dart b/packages/cloud_firestore/example/test_driver/cloud_firestore.dart index 5cf8a33d31f0..12460b7ad07f 100644 --- a/packages/cloud_firestore/example/test_driver/cloud_firestore.dart +++ b/packages/cloud_firestore/example/test_driver/cloud_firestore.dart @@ -128,7 +128,8 @@ void main() { expect(snapshot.metadata.isFromCache, true); expect(snapshot.data['hello'], 'world'); - while (snapshot.metadata.hasPendingWrites || snapshot.metadata.isFromCache) { + while ( + snapshot.metadata.hasPendingWrites || snapshot.metadata.isFromCache) { snapshot = await snapshotsWithMetadataChanges.take(1).first; } expect(snapshot.data['hello'], 'world');