Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public abstract class SpecTestCase implements RemoteStoreCallback {
Collections.synchronizedList(new ArrayList<>());
private final List<DocumentKey> rejectedDocs = Collections.synchronizedList(new ArrayList<>());
private List<EventListener<Void>> snapshotsInSyncListeners;
private int waitForPendingWriteEvents = 0;
private int snapshotsInSyncEvents = 0;

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

private void doWaitForPendingWrites() {
final TaskCompletionSource<Void> source = new TaskCompletionSource<>();
source
.getTask()
.addOnSuccessListener(backgroundExecutor, result -> waitForPendingWriteEvents += 1);
syncEngine.registerPendingWritesTask(source);
}

private void doAddSnapshotsInSyncListener() {
EventListener<Void> eventListener =
(Void v, FirebaseFirestoreException error) -> snapshotsInSyncEvents += 1;
Expand Down Expand Up @@ -813,6 +822,8 @@ private void doStep(JSONObject step) throws Exception {
doWriteAck(step.getJSONObject("writeAck"));
} else if (step.has("failWrite")) {
doFailWrite(step.getJSONObject("failWrite"));
} else if (step.has("waitForPendingWrites")) {
doWaitForPendingWrites();
} else if (step.has("runTimer")) {
doRunTimer(step.getString("runTimer"));
} else if (step.has("enableNetwork")) {
Expand Down Expand Up @@ -986,6 +997,11 @@ private void validateSnapshotsInSyncEvents(int expectedCount) {
snapshotsInSyncEvents = 0;
}

private void validateWaitForPendingWritesEvents(int expectedCount) {
assertEquals(expectedCount, waitForPendingWriteEvents);
waitForPendingWriteEvents = 0;
}

private void validateUserCallbacks(@Nullable JSONObject expected) throws JSONException {
if (expected != null && expected.has("userCallbacks")) {
JSONObject userCallbacks = expected.getJSONObject("userCallbacks");
Expand Down Expand Up @@ -1116,6 +1132,8 @@ private void runSteps(JSONArray steps, JSONObject config) throws Exception {
step.remove("expectedState");
int expectedSnapshotsInSyncEvents = step.optInt("expectedSnapshotsInSyncEvents");
step.remove("expectedSnapshotsInSyncEvents");
int expectedWaitForPendingWritesEvents = step.optInt("expectedWaitForPendingWritesEvents");
step.remove("expectedWaitForPendingWritesEvents");

log(" Doing step " + step);
doStep(step);
Expand All @@ -1133,6 +1151,7 @@ private void runSteps(JSONArray steps, JSONObject config) throws Exception {
}
validateExpectedState(expectedState);
validateSnapshotsInSyncEvents(expectedSnapshotsInSyncEvents);
validateWaitForPendingWritesEvents(expectedWaitForPendingWritesEvents);
events.clear();
acknowledgedDocs.clear();
rejectedDocs.clear();
Expand Down
Loading