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 @@ -14,6 +14,7 @@

package com.google.firebase.appdistribution.impl;

import androidx.annotation.VisibleForTesting;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.TaskCompletionSource;
import com.google.firebase.annotations.concurrent.Lightweight;
Expand Down Expand Up @@ -66,6 +67,20 @@ Task<T> getOrCreateTask(TaskProducer<T> producer) {
return taskCompletionSource.getTask();
}

/**
* Returns a task that completes when this object's internal sequential executor has finished
* processing all enqueued operations.
* <p>
* This method should never be called in production code; however, it is useful in unit tests to
* ensure deterministic behavior.
*/
@VisibleForTesting
Task<Void> newTaskForSequentialExecutorFlush() {
TaskCompletionSource<Void> taskCompletionSource = new TaskCompletionSource<>();
sequentialExecutor.execute(() -> taskCompletionSource.setResult(null));
return taskCompletionSource.getTask();
}

private static <T> boolean isOngoing(Task<T> task) {
return task != null && !task.isComplete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public void checkForNewRelease_whenCalledMultipleTimes_onlyFetchesReleasesOnce()

// Don't set the result until after calling twice, to make sure that the task from the first
// call is still ongoing.
awaitTask(newReleaseFetcher.cachedCheckForNewRelease.newTaskForSequentialExecutorFlush());
task.setResult(null);
awaitTask(checkForNewReleaseTask1);
awaitTask(checkForNewReleaseTask2);
Expand Down