Fix flaky test for ConnectivityServiceTest#testPartialConnectivity
There are 2 problems will make testPartialConnectivity flaky: 1. If we call setNetworkValid() before expectCapabilitiesWith(), there may be a timing issue that network will become VALID before NetworkMonitor send PARTIAL_CONNECTIVITY to ConnectivityService. Solution: We should set network to valid after ConnectivityService received NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY to ensure NetworkMonitor will send PARTIAL_CONNECTIVITY to ConnectivityService first then send VALID. 2. When test case call explicitlySelected(true) first then call connect(true), NetworkMonitor will report the network validation test result twice because ConnectivityServiceTest() will trigger notifyNetworkTested() when setAcceptPartialConnectivity() is called, it may cause a timing that before the second test result send to ConnectivityService, connect() already called setNetworkInvalid. So, NET_CAPABILITY_VALIDATED will be removed and ConnectivityService will trigger onCapabilitiesChanged() unexpectedly. Solution: Don't trigger notifyNetworkTested() when setAcceptPartialConnectivity() is called. If there is needed, use mCm.reportNetworkConnectivity() to report the test result instead. Bug: 128426024 Test: 1. atest FrameworksNetTests: \ ConnectivityServiceTest#testPartialConnectivity \ --generate-new-metrics 1000 Change-Id: I7200528378201a3c7c09a78ff827b41f2741dfa1
Loading
Please register or sign in to comment