DO NOT MERGE: ConnectivityServiceTest: mark flaky test as such
This patch extracts into its own independent test a test sub-block looking
for a race condition when not waiting on handlers to become idle:
there is no way to prevent the race from not happening when looking for
it this way. This makes the test flakky.
This new independent test is tagged with @FlakkyTest(tolerance = 3).
Test: ConnectivityServiceTest passes, with higher probability.
Bug: 31479480
(cherry picked from commit 144810b6cf)
Change-Id: I32632bb763585c23f1de5bb1811a384a35bf9f64
This commit is contained in:
committed by
Lorenzo Colitti
parent
ee83e11aeb
commit
30c0460727
@@ -68,6 +68,7 @@ import android.os.Process;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.Settings;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.FlakyTest;
|
||||
import android.test.mock.MockContentResolver;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
@@ -215,8 +216,20 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
mService.waitForIdle();
|
||||
assertEquals(i, mCm.getNetworkCapabilities(n).getSignalStrength());
|
||||
}
|
||||
}
|
||||
|
||||
@FlakyTest(tolerance = 3)
|
||||
public void testNotWaitingForIdleCausesRaceConditions() {
|
||||
// Bring up a network that we can use to send messages to ConnectivityService.
|
||||
ConditionVariable cv = waitForConnectivityBroadcasts(1);
|
||||
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
||||
mWiFiNetworkAgent.connect(false);
|
||||
waitFor(cv);
|
||||
Network n = mWiFiNetworkAgent.getNetwork();
|
||||
assertNotNull(n);
|
||||
|
||||
// Ensure that not calling waitForIdle causes a race condition.
|
||||
final int attempts = 50; // Causes the test to take about 200ms on bullhead-eng.
|
||||
for (int i = 0; i < attempts; i++) {
|
||||
mWiFiNetworkAgent.setSignalStrength(i);
|
||||
if (i != mCm.getNetworkCapabilities(n).getSignalStrength()) {
|
||||
|
||||
Reference in New Issue
Block a user