Use utility method to execute things on the handler
Replace Handler.post() with visibleOnHandlerTread(). Test: atest FrameworksNetTests Change-Id: I3a2f166d939db8ed6ac7fbb1cb9306256ae22189
This commit is contained in:
@@ -408,22 +408,22 @@ public class AutomaticOnOffKeepaliveTrackerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsAnyTcpSocketConnected_withTargetNetId() throws Exception {
|
public void testIsAnyTcpSocketConnected_withTargetNetId() throws Exception {
|
||||||
setupResponseWithSocketExisting();
|
setupResponseWithSocketExisting();
|
||||||
mTestHandler.post(
|
assertTrue(visibleOnHandlerThread(mTestHandler,
|
||||||
() -> assertTrue(mAOOKeepaliveTracker.isAnyTcpSocketConnected(TEST_NETID)));
|
() -> mAOOKeepaliveTracker.isAnyTcpSocketConnected(TEST_NETID)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAnyTcpSocketConnected_withIncorrectNetId() throws Exception {
|
public void testIsAnyTcpSocketConnected_withIncorrectNetId() throws Exception {
|
||||||
setupResponseWithSocketExisting();
|
setupResponseWithSocketExisting();
|
||||||
mTestHandler.post(
|
assertFalse(visibleOnHandlerThread(mTestHandler,
|
||||||
() -> assertFalse(mAOOKeepaliveTracker.isAnyTcpSocketConnected(OTHER_NETID)));
|
() -> mAOOKeepaliveTracker.isAnyTcpSocketConnected(OTHER_NETID)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAnyTcpSocketConnected_noSocketExists() throws Exception {
|
public void testIsAnyTcpSocketConnected_noSocketExists() throws Exception {
|
||||||
setupResponseWithoutSocketExisting();
|
setupResponseWithoutSocketExisting();
|
||||||
mTestHandler.post(
|
assertFalse(visibleOnHandlerThread(mTestHandler,
|
||||||
() -> assertFalse(mAOOKeepaliveTracker.isAnyTcpSocketConnected(TEST_NETID)));
|
() -> mAOOKeepaliveTracker.isAnyTcpSocketConnected(TEST_NETID)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void triggerEventKeepalive(int slot, int reason) {
|
private void triggerEventKeepalive(int slot, int reason) {
|
||||||
@@ -500,9 +500,7 @@ public class AutomaticOnOffKeepaliveTrackerTest {
|
|||||||
final AlarmManager.OnAlarmListener listener = listenerCaptor.getValue();
|
final AlarmManager.OnAlarmListener listener = listenerCaptor.getValue();
|
||||||
|
|
||||||
// For realism, the listener should be posted on the handler
|
// For realism, the listener should be posted on the handler
|
||||||
mTestHandler.post(() -> listener.onAlarm());
|
visibleOnHandlerThread(mTestHandler, () -> listener.onAlarm());
|
||||||
// Wait for the listener to be called. The listener enqueues a message to the handler.
|
|
||||||
HandlerUtils.waitForIdle(mTestHandler, TIMEOUT_MS);
|
|
||||||
// Wait for the message posted by the listener to be processed.
|
// Wait for the message posted by the listener to be processed.
|
||||||
HandlerUtils.waitForIdle(mTestHandler, TIMEOUT_MS);
|
HandlerUtils.waitForIdle(mTestHandler, TIMEOUT_MS);
|
||||||
|
|
||||||
@@ -525,8 +523,7 @@ public class AutomaticOnOffKeepaliveTrackerTest {
|
|||||||
|
|
||||||
doReturn(METRICS_COLLECTION_DURATION_MS).when(mDependencies).getElapsedRealtime();
|
doReturn(METRICS_COLLECTION_DURATION_MS).when(mDependencies).getElapsedRealtime();
|
||||||
// For realism, the listener should be posted on the handler
|
// For realism, the listener should be posted on the handler
|
||||||
mTestHandler.post(() -> listener.onAlarm());
|
visibleOnHandlerThread(mTestHandler, () -> listener.onAlarm());
|
||||||
HandlerUtils.waitForIdle(mTestHandler, TIMEOUT_MS);
|
|
||||||
|
|
||||||
verify(mKeepaliveStatsTracker).writeAndResetMetrics();
|
verify(mKeepaliveStatsTracker).writeAndResetMetrics();
|
||||||
// Alarm is rescheduled.
|
// Alarm is rescheduled.
|
||||||
|
|||||||
Reference in New Issue
Block a user