Skip to content

Commit fc3492d

Browse files
Import spec tests
Port of firebase/firebase-js-sdk#3821
1 parent 34df09d commit fc3492d

File tree

4 files changed

+857
-0
lines changed

4 files changed

+857
-0
lines changed

firebase-firestore/src/test/java/com/google/firebase/firestore/spec/SpecTestCase.java

+19
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ public abstract class SpecTestCase implements RemoteStoreCallback {
213213
Collections.synchronizedList(new ArrayList<>());
214214
private final List<DocumentKey> rejectedDocs = Collections.synchronizedList(new ArrayList<>());
215215
private List<EventListener<Void>> snapshotsInSyncListeners;
216+
private int waitForPendingWriteEvents = 0;
216217
private int snapshotsInSyncEvents = 0;
217218

218219
/** An executor to use for test callbacks. */
@@ -534,6 +535,14 @@ private void doDelete(String key) throws Exception {
534535
doMutation(deleteMutation(key));
535536
}
536537

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+
537546
private void doAddSnapshotsInSyncListener() {
538547
EventListener<Void> eventListener =
539548
(Void v, FirebaseFirestoreException error) -> snapshotsInSyncEvents += 1;
@@ -813,6 +822,8 @@ private void doStep(JSONObject step) throws Exception {
813822
doWriteAck(step.getJSONObject("writeAck"));
814823
} else if (step.has("failWrite")) {
815824
doFailWrite(step.getJSONObject("failWrite"));
825+
} else if (step.has("waitForPendingWrites")) {
826+
doWaitForPendingWrites();
816827
} else if (step.has("runTimer")) {
817828
doRunTimer(step.getString("runTimer"));
818829
} else if (step.has("enableNetwork")) {
@@ -986,6 +997,11 @@ private void validateSnapshotsInSyncEvents(int expectedCount) {
986997
snapshotsInSyncEvents = 0;
987998
}
988999

1000+
private void validateWaitForPendingWritesEvents(int expectedCount) {
1001+
assertEquals(expectedCount, waitForPendingWriteEvents);
1002+
waitForPendingWriteEvents = 0;
1003+
}
1004+
9891005
private void validateUserCallbacks(@Nullable JSONObject expected) throws JSONException {
9901006
if (expected != null && expected.has("userCallbacks")) {
9911007
JSONObject userCallbacks = expected.getJSONObject("userCallbacks");
@@ -1116,6 +1132,8 @@ private void runSteps(JSONArray steps, JSONObject config) throws Exception {
11161132
step.remove("expectedState");
11171133
int expectedSnapshotsInSyncEvents = step.optInt("expectedSnapshotsInSyncEvents");
11181134
step.remove("expectedSnapshotsInSyncEvents");
1135+
int expectedWaitForPendingWritesEvents = step.optInt("expectedWaitForPendingWritesEvents");
1136+
step.remove("expectedWaitForPendingWritesEvents");
11191137

11201138
log(" Doing step " + step);
11211139
doStep(step);
@@ -1133,6 +1151,7 @@ private void runSteps(JSONArray steps, JSONObject config) throws Exception {
11331151
}
11341152
validateExpectedState(expectedState);
11351153
validateSnapshotsInSyncEvents(expectedSnapshotsInSyncEvents);
1154+
validateWaitForPendingWritesEvents(expectedWaitForPendingWritesEvents);
11361155
events.clear();
11371156
acknowledgedDocs.clear();
11381157
rejectedDocs.clear();

0 commit comments

Comments
 (0)