[Thread] run ThreadNetworkControllerServiceTest tests in a single thread
@Test annotated methods are running in threads like
"Thread[Time-limited test,5,main]" which is created by FailOnTimeout.java,
while @Before annotated setUp() is running in thread
"Thread[Instr: androidx.test.runner.AndroidJUnitRunner,5,main]" which is
created by AndroidJUnitRunner.
The issue is that there are code in ThreadNetworkControllerService
checking all its methods runs on the thread associated to the provided
handler. This constraint doesn't hold in this unit test because
TestLooper runs all the posted tasks on the current thread rather than
the thread associated to its backed looper. So the tests will fail with
Log.wtf() which terminates the process on eng build.
This commit fixes this issue by annotating the test class with
@UiThreadTest to force methods annotated with @Before, @After and @Test
to run on the main / UI thread.
Test: run this test class on aosp_cf_x86_64_phone-trunk_staging-eng
Bug: 342092067
Change-Id: I7d75de5ac31234f3051e9ed332da33c1da6a8c98
2 files changed