Fix memory leak in test LimitOffsetRxPagingSourceTest

ensure all room tasks are drained at the end of tests

Test: ./gradlew :room:room-paging-rxjava3:cC
Fixes: 232572628
Change-Id: I089c18041a5950f6e354ccd27bb5fb5954a800c7
diff --git a/room/room-paging-rxjava3/src/androidTest/kotlin/androidx/room/paging/rxjava3/LimitOffsetRxPagingSourceTest.kt b/room/room-paging-rxjava3/src/androidTest/kotlin/androidx/room/paging/rxjava3/LimitOffsetRxPagingSourceTest.kt
index 405e1ac..931185e 100644
--- a/room/room-paging-rxjava3/src/androidTest/kotlin/androidx/room/paging/rxjava3/LimitOffsetRxPagingSourceTest.kt
+++ b/room/room-paging-rxjava3/src/androidTest/kotlin/androidx/room/paging/rxjava3/LimitOffsetRxPagingSourceTest.kt
@@ -55,6 +55,7 @@
 import kotlinx.coroutines.rx3.await
 import kotlinx.coroutines.test.advanceUntilIdle
 import kotlinx.coroutines.test.runTest
+import org.junit.After
 import org.junit.Rule
 import org.junit.Test
 import org.junit.runner.RunWith
@@ -70,6 +71,12 @@
     @Rule
     val countingTaskExecutorRule = CountingTaskExecutorRule()
 
+    @After
+    fun tearDown() {
+        countingTaskExecutorRule.drainTasks(500, TimeUnit.MILLISECONDS)
+        assertTrue(countingTaskExecutorRule.isIdle)
+    }
+
     @Test
     fun initialLoad_empty() = setupAndRun { db ->
         val pagingSource = LimitOffsetRxPagingSourceImpl(db)
@@ -466,6 +473,8 @@
             assertTrue(job.isCancelled)
             assertTrue(isDisposed)
         }
+        // need to drain before closing testDb or else will throw SQLiteConnectionPool exception
+        countingTaskExecutorRule.drainTasks(500, TimeUnit.MILLISECONDS)
         testDb.close()
     }
 
@@ -543,13 +552,7 @@
         runTest {
             test(db)
         }
-        tearDown(db)
-    }
-
-    private fun tearDown(db: LimitOffsetTestDb) {
-        if (db.isOpen) db.close()
-        countingTaskExecutorRule.drainTasks(500, TimeUnit.MILLISECONDS)
-        assertTrue(countingTaskExecutorRule.isIdle)
+        db.close()
     }
 }