Assert on executor being idle in WriteAheadLoggingTest
Bug: 211599322
Test: WriteAheadLoggingTest
Change-Id: I1e7a722b8205591a86ea1216286e59fa0261eee1
diff --git a/room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/WriteAheadLoggingTest.java b/room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/WriteAheadLoggingTest.java
index 6d9f4b5..a5ba88e 100644
--- a/room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/WriteAheadLoggingTest.java
+++ b/room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/WriteAheadLoggingTest.java
@@ -32,6 +32,7 @@
import android.database.Cursor;
import androidx.annotation.NonNull;
+import androidx.arch.core.executor.testing.CountingTaskExecutorRule;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
import androidx.room.InvalidationTracker;
@@ -49,6 +50,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -61,6 +63,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
@RunWith(AndroidJUnit4.class)
@LargeTest
@@ -70,6 +73,9 @@
private static final String DATABASE_NAME = "wal.db";
private TestDatabase mDatabase;
+ @Rule
+ public CountingTaskExecutorRule countingTaskExecutorRule = new CountingTaskExecutorRule();
+
@Before
public void openDatabase() {
Context context = ApplicationProvider.getApplicationContext();
@@ -80,7 +86,10 @@
}
@After
- public void closeDatabase() {
+ public void closeDatabase() throws InterruptedException, TimeoutException {
+ countingTaskExecutorRule.drainTasks(500, TimeUnit.MILLISECONDS);
+ assertThat(countingTaskExecutorRule.isIdle(), is(true));
+
mDatabase.close();
Context context = ApplicationProvider.getApplicationContext();
context.deleteDatabase(DATABASE_NAME);