Fix flake in testConnectivityDiagnosticsCallbackOnConnectivityReported
The test relied on waitForIdle to ensure diagnostics callbacks were called, but as this may require several iterations in the handler queue, this makes the test unreliable. Use mockito timeouts on the verify() calls instead. Bug: 192651465 Change-Id: Iae1704af7ae3649eae301c6aee223ac753629d55 Test: atest ConnectivityServiceTest
This commit is contained in:
@@ -10213,10 +10213,7 @@ public class ConnectivityServiceTest {
|
||||
mService.registerConnectivityDiagnosticsCallback(
|
||||
mConnectivityDiagnosticsCallback, request, mContext.getPackageName());
|
||||
|
||||
// Block until all other events are done processing.
|
||||
HandlerUtils.waitForIdle(mCsHandlerThread, TIMEOUT_MS);
|
||||
|
||||
verify(mConnectivityDiagnosticsCallback)
|
||||
verify(mConnectivityDiagnosticsCallback, timeout(TIMEOUT_MS))
|
||||
.onConnectivityReportAvailable(argThat(report -> {
|
||||
return INTERFACE_NAME.equals(report.getLinkProperties().getInterfaceName())
|
||||
&& report.getNetworkCapabilities().hasTransport(TRANSPORT_CELLULAR);
|
||||
@@ -10264,12 +10261,10 @@ public class ConnectivityServiceTest {
|
||||
throws Exception {
|
||||
setUpConnectivityDiagnosticsCallback();
|
||||
|
||||
// Block until all other events are done processing.
|
||||
HandlerUtils.waitForIdle(mCsHandlerThread, TIMEOUT_MS);
|
||||
|
||||
// Verify onConnectivityReport fired
|
||||
verify(mConnectivityDiagnosticsCallback).onConnectivityReportAvailable(
|
||||
argThat(report -> areConnDiagCapsRedacted(report.getNetworkCapabilities())));
|
||||
verify(mConnectivityDiagnosticsCallback, timeout(TIMEOUT_MS))
|
||||
.onConnectivityReportAvailable(argThat(report ->
|
||||
areConnDiagCapsRedacted(report.getNetworkCapabilities())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -10280,11 +10275,8 @@ public class ConnectivityServiceTest {
|
||||
// cellular network agent
|
||||
mCellNetworkAgent.notifyDataStallSuspected();
|
||||
|
||||
// Block until all other events are done processing.
|
||||
HandlerUtils.waitForIdle(mCsHandlerThread, TIMEOUT_MS);
|
||||
|
||||
// Verify onDataStallSuspected fired
|
||||
verify(mConnectivityDiagnosticsCallback).onDataStallSuspected(
|
||||
verify(mConnectivityDiagnosticsCallback, timeout(TIMEOUT_MS)).onDataStallSuspected(
|
||||
argThat(report -> areConnDiagCapsRedacted(report.getNetworkCapabilities())));
|
||||
}
|
||||
|
||||
@@ -10299,23 +10291,19 @@ public class ConnectivityServiceTest {
|
||||
final boolean hasConnectivity = true;
|
||||
mService.reportNetworkConnectivity(n, hasConnectivity);
|
||||
|
||||
// Block until all other events are done processing.
|
||||
HandlerUtils.waitForIdle(mCsHandlerThread, TIMEOUT_MS);
|
||||
|
||||
// Verify onNetworkConnectivityReported fired
|
||||
verify(mConnectivityDiagnosticsCallback)
|
||||
verify(mConnectivityDiagnosticsCallback, timeout(TIMEOUT_MS))
|
||||
.onNetworkConnectivityReported(eq(n), eq(hasConnectivity));
|
||||
verify(mConnectivityDiagnosticsCallback).onConnectivityReportAvailable(
|
||||
argThat(report -> areConnDiagCapsRedacted(report.getNetworkCapabilities())));
|
||||
verify(mConnectivityDiagnosticsCallback, timeout(TIMEOUT_MS))
|
||||
.onConnectivityReportAvailable(
|
||||
argThat(report ->
|
||||
areConnDiagCapsRedacted(report.getNetworkCapabilities())));
|
||||
|
||||
final boolean noConnectivity = false;
|
||||
mService.reportNetworkConnectivity(n, noConnectivity);
|
||||
|
||||
// Block until all other events are done processing.
|
||||
HandlerUtils.waitForIdle(mCsHandlerThread, TIMEOUT_MS);
|
||||
|
||||
// Wait for onNetworkConnectivityReported to fire
|
||||
verify(mConnectivityDiagnosticsCallback)
|
||||
verify(mConnectivityDiagnosticsCallback, timeout(TIMEOUT_MS))
|
||||
.onNetworkConnectivityReported(eq(n), eq(noConnectivity));
|
||||
|
||||
// Also expect a ConnectivityReport after NetworkMonitor asynchronously re-validates
|
||||
@@ -10353,9 +10341,6 @@ public class ConnectivityServiceTest {
|
||||
final boolean noConnectivity = false;
|
||||
doAsUid(Process.myUid() + 1, () -> mService.reportNetworkConnectivity(n, noConnectivity));
|
||||
|
||||
// Block until all other events are done processing.
|
||||
HandlerUtils.waitForIdle(mCsHandlerThread, TIMEOUT_MS);
|
||||
|
||||
// Wait for onNetworkConnectivityReported to fire
|
||||
verify(mConnectivityDiagnosticsCallback, timeout(TIMEOUT_MS))
|
||||
.onNetworkConnectivityReported(eq(n), eq(noConnectivity));
|
||||
|
||||
Reference in New Issue
Block a user