Flow query emitting null test.

Test: FlowQueryTest
Bug: 139768558
Change-Id: I421a78eab89ed3ec62470f65ea5d1e7fc0fa7879
diff --git a/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt b/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt
index 8dae07b0..1d8cd6b 100644
--- a/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt
+++ b/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt
@@ -388,4 +388,7 @@
     @Transaction
     @Query("SELECT * FROM book")
     fun getBooksFlowInTransaction(): Flow<List<Book>>
+
+    @Query("SELECT * FROM book WHERE bookId = :id")
+    fun getOneBooksFlow(id: String): Flow<Book?>
 }
diff --git a/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/FlowQueryTest.kt b/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/FlowQueryTest.kt
index fb56ad1..2753b3d 100644
--- a/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/FlowQueryTest.kt
+++ b/room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/FlowQueryTest.kt
@@ -254,4 +254,42 @@
         latch.await()
         job.cancelAndJoin()
     }
+
+    @Test
+    fun receiveBook_async_update_null() = runBlocking {
+        booksDao.addAuthors(TestUtil.AUTHOR_1)
+        booksDao.addPublishers(TestUtil.PUBLISHER)
+        booksDao.addBooks(TestUtil.BOOK_1)
+
+        val firstResultLatch = CountDownLatch(1)
+        val secondResultLatch = CountDownLatch(1)
+        val results = mutableListOf<Book?>()
+        val job = async(Dispatchers.IO) {
+            booksDao.getOneBooksFlow(TestUtil.BOOK_1.bookId).collect {
+                when (results.size) {
+                    0 -> {
+                        results.add(it)
+                        firstResultLatch.countDown()
+                    }
+                    1 -> {
+                        results.add(it)
+                        secondResultLatch.countDown()
+                    }
+                    else -> fail("Should have only collected 2 results.")
+                }
+            }
+        }
+
+        firstResultLatch.await()
+        booksDao.deleteBookSuspend(TestUtil.BOOK_1)
+
+        secondResultLatch.await()
+        assertThat(results.size).isEqualTo(2)
+        assertThat(results[0])
+            .isEqualTo(TestUtil.BOOK_1)
+        assertThat(results[1])
+            .isNull()
+
+        job.cancelAndJoin()
+    }
 }
\ No newline at end of file