Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
Component used: androidx.work.CoroutineWorker (androidx.work:work-runtime-ktx)
Version used: 2.9.0
Devices/Android versions reproduced on: Android Emulator API Version 33
Long running work with constraints gets immediately cancelled after calling
setForeground
in instrumented tests. This makes such Work difficult to test in instrumented tests.Following the documentation on long running Android work request I call
setForeground
to allow long-running work.Following the official documentation I can use a TestDriver to set the conditions met.
setConditionsMet
allows the work to start running, but immediately after calling setForeground` the Work gets cancelled anyway.The only way that I have found to test this kind of Work is to remove the constraints. Which is obviously not ideal as I cannot test the constraints themselves.
The following stand-alone test demonstrates the problem: