Assigned
Status Update
Comments
da...@google.com <da...@google.com>
jo...@gmail.com <jo...@gmail.com> #2
Forgot to note the environment.
This crash occurs on only API 21.
This crash occurs on only API 21.
ma...@gmail.com <ma...@gmail.com> #3
This crash occurs on API 22 and 23 when the user doesn't have Google Play installed. Related discussions: https://stackoverflow.com/q/41025200/842697
Description
Version used: Room 2.1.0, Lifecycle 2.2.0-alpha01, Arch Core 2.1.0-beta01
Devices/Android versions reproduced on: Emulator API 28
The following test won't run, when I use a suspended Dao Function annotated with @Transaction in it.
class RecurrenceManagerTest : DatabaseTest() {
@Rule
@JvmField
val instantTaskExecutorRule = InstantTaskExecutorRule()
var recurringEntryId: Long = -1
@Before
override fun setup() {
super.setup() // only initialized the db
val recurringEntry = RecurringEntry(
recurrence = Recurrence(DATE.toEpochMilli(), Recurrence.DAILY)
)
recurringEntryId = runBlocking { db.recurringEntryDao().insert(recurringEntry) }
val recurringBookEntry = BookEntry.create(
title = TITLE,
date = DATE,
value = VALUE,
isPaid = IS_PAID,
notes = NOTES,
entryType = ENTRY_TYPE,
categoryId = CATEGORY_ID,
contacts = CONTACTS,
recurringEntryId = recurringEntryId
)
runBlocking {
db.bookEntryDao().insert(recurringBookEntry) //
}
}
@Test
fun testInsertRecurrencesAndSchedule() = runBlocking {
var recurringEntry = db.recurringEntryDao().get(recurringEntryId) //
assertThat(recurringEntry, notNullValue())
RecurrenceManager.insertRecurrencesAndSchedule(ApplicationProvider.getApplicationContext(), db, recurringEntry!!) //
val bookEntries = db.bookEntryDao().getBookEntries().liveDataValue() //
}
}
This is the function at #1, and also in #3:
@Transaction
suspend fun insert(bookEntry: BookEntry): Long {
val id = insert(bookEntry.entity)
bookEntry.embeddedContacts?.apply {
forEach {
it.bookEntryId = id
}
}?.let {
insert(it)
}
return id
}
It looks like the insert function at #1 causes the test running an infinite loop.
Code at #2 is never reached.
I figured out, that when removing the InstantTaskExecutorRule, the test runs correctly until #4.
There, I try to fetch the database items from LiveData using the method from googlesamples:
When reaching #4, the error " java.lang.IllegalStateException: Cannot invoke observeForever on a background thread" is thrown.