@@ -213,6 +213,7 @@ public abstract class SpecTestCase implements RemoteStoreCallback {
213
213
Collections .synchronizedList (new ArrayList <>());
214
214
private final List <DocumentKey > rejectedDocs = Collections .synchronizedList (new ArrayList <>());
215
215
private List <EventListener <Void >> snapshotsInSyncListeners ;
216
+ private int waitForPendingWriteEvents = 0 ;
216
217
private int snapshotsInSyncEvents = 0 ;
217
218
218
219
/** An executor to use for test callbacks. */
@@ -534,6 +535,14 @@ private void doDelete(String key) throws Exception {
534
535
doMutation (deleteMutation (key ));
535
536
}
536
537
538
+ private void doWaitForPendingWrites () {
539
+ final TaskCompletionSource <Void > source = new TaskCompletionSource <>();
540
+ source
541
+ .getTask ()
542
+ .addOnSuccessListener (backgroundExecutor , result -> waitForPendingWriteEvents += 1 );
543
+ syncEngine .registerPendingWritesTask (source );
544
+ }
545
+
537
546
private void doAddSnapshotsInSyncListener () {
538
547
EventListener <Void > eventListener =
539
548
(Void v , FirebaseFirestoreException error ) -> snapshotsInSyncEvents += 1 ;
@@ -813,6 +822,8 @@ private void doStep(JSONObject step) throws Exception {
813
822
doWriteAck (step .getJSONObject ("writeAck" ));
814
823
} else if (step .has ("failWrite" )) {
815
824
doFailWrite (step .getJSONObject ("failWrite" ));
825
+ } else if (step .has ("waitForPendingWrites" )) {
826
+ doWaitForPendingWrites ();
816
827
} else if (step .has ("runTimer" )) {
817
828
doRunTimer (step .getString ("runTimer" ));
818
829
} else if (step .has ("enableNetwork" )) {
@@ -986,6 +997,11 @@ private void validateSnapshotsInSyncEvents(int expectedCount) {
986
997
snapshotsInSyncEvents = 0 ;
987
998
}
988
999
1000
+ private void validateWaitForPendingWritesEvents (int expectedCount ) {
1001
+ assertEquals (expectedCount , waitForPendingWriteEvents );
1002
+ waitForPendingWriteEvents = 0 ;
1003
+ }
1004
+
989
1005
private void validateUserCallbacks (@ Nullable JSONObject expected ) throws JSONException {
990
1006
if (expected != null && expected .has ("userCallbacks" )) {
991
1007
JSONObject userCallbacks = expected .getJSONObject ("userCallbacks" );
@@ -1116,6 +1132,8 @@ private void runSteps(JSONArray steps, JSONObject config) throws Exception {
1116
1132
step .remove ("expectedState" );
1117
1133
int expectedSnapshotsInSyncEvents = step .optInt ("expectedSnapshotsInSyncEvents" );
1118
1134
step .remove ("expectedSnapshotsInSyncEvents" );
1135
+ int expectedWaitForPendingWritesEvents = step .optInt ("expectedWaitForPendingWritesEvents" );
1136
+ step .remove ("expectedWaitForPendingWritesEvents" );
1119
1137
1120
1138
log (" Doing step " + step );
1121
1139
doStep (step );
@@ -1133,6 +1151,7 @@ private void runSteps(JSONArray steps, JSONObject config) throws Exception {
1133
1151
}
1134
1152
validateExpectedState (expectedState );
1135
1153
validateSnapshotsInSyncEvents (expectedSnapshotsInSyncEvents );
1154
+ validateWaitForPendingWritesEvents (expectedWaitForPendingWritesEvents );
1136
1155
events .clear ();
1137
1156
acknowledgedDocs .clear ();
1138
1157
rejectedDocs .clear ();
0 commit comments