azabost
10/24/2023, 12:49 PMChristian Ricardo
10/24/2023, 5:33 PMtestScheduler.advanceUntilIdle()
after the runCurrent()
but I can't try it because I need to implement all that 🤣azabost
10/24/2023, 7:05 PMadvanceUntilIdle()
didn't help. I think the problem was with how Room executes the queries, e.g. it runs them on some arbitrary Executor
and the test coroutine is not able to wait until it completes.
I was able to work around the problem by using a combination of both:
• InstantTaskExecutorRule
• allowMainThreadQueries()
I also followed this issue on GitHub where one of the problems being discussed is this:Christian Ricardo
10/24/2023, 7:33 PMExecutor
is not always arbitrary, you can set your own with the DatabaseConfiguration
on init()
if I'm not wrong 🤔azabost
10/24/2023, 8:15 PMInstantTaskExecutorRule
?azabost
10/24/2023, 8:16 PMChristian Ricardo
10/24/2023, 8:25 PMallowMainThreadQueries()
azabost
10/24/2023, 8:27 PMallowMainThreadQueries
because InstantTaskExecutorRule
returns a TaskExecutor
with
@Override
public boolean isMainThread() {
return true;
}
so Room thinks I query it on the main thread 🤦♂️ and throws exceptions
btw for safety I set allowMainThreadQueries
only in tests, not in production code.Christian Ricardo
10/24/2023, 8:29 PM