Skip to content

Commit 08eb7dd

Browse files
Tsu Chiang ChuangAndroid (Google) Code Review
authored andcommitted
Merge "extending timeout to stabilize tests" into ics-mr1
2 parents 197fe26 + a8c57bf commit 08eb7dd

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

core/tests/bandwidthtests/src/com/android/bandwidthtest/BandwidthTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ protected void tearDown() throws Exception {
9090
*/
9191
@LargeTest
9292
public void testWifiDownload() throws Exception {
93+
mConnectionUtil.wifiTestInit();
9394
assertTrue("Could not connect to wifi!", setDeviceWifiAndAirplaneMode(mSsid));
9495
downloadFile();
9596
}
@@ -143,6 +144,7 @@ protected void downloadFile() throws Exception {
143144
*/
144145
@LargeTest
145146
public void testWifiUpload() throws Exception {
147+
mConnectionUtil.wifiTestInit();
146148
assertTrue(setDeviceWifiAndAirplaneMode(mSsid));
147149
uploadFile();
148150
}
@@ -197,6 +199,7 @@ protected void uploadFile() throws Exception {
197199
*/
198200
@LargeTest
199201
public void testWifiDownloadWithDownloadManager() throws Exception {
202+
mConnectionUtil.wifiTestInit();
200203
assertTrue(setDeviceWifiAndAirplaneMode(mSsid));
201204
downloadFileUsingDownloadManager();
202205
}
@@ -286,6 +289,8 @@ public boolean setDeviceWifiAndAirplaneMode(String ssid) {
286289
* @return true if we successfully connect to mobile data.
287290
*/
288291
public boolean hasMobileData() {
292+
assertTrue(mConnectionUtil.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
293+
State.CONNECTED, ConnectionUtil.LONG_TIMEOUT));
289294
assertTrue("Not connected to mobile", mConnectionUtil.isConnectedToMobile());
290295
assertFalse("Still connected to wifi.", mConnectionUtil.isConnectedToWifi());
291296
return mConnectionUtil.hasData();

core/tests/bandwidthtests/src/com/android/bandwidthtest/util/ConnectionUtil.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class ConnectionUtil {
5757
private static final int WAIT_FOR_SCAN_RESULT = 10 * 1000; // 10 seconds
5858
private static final int WIFI_SCAN_TIMEOUT = 50 * 1000;
5959
public static final int SHORT_TIMEOUT = 5 * 1000;
60-
public static final int LONG_TIMEOUT = 10 * 1000;
60+
public static final int LONG_TIMEOUT = 120 * 1000; // 2 minutes
6161
private ConnectivityReceiver mConnectivityReceiver = null;
6262
private WifiReceiver mWifiReceiver = null;
6363
private DownloadReceiver mDownloadReceiver = null;
@@ -118,8 +118,14 @@ public void initialize() throws Exception {
118118

119119
initializeNetworkStates();
120120

121-
mWifiManager.setWifiEnabled(true);
122121

122+
}
123+
124+
/**
125+
* Additional initialization needed for wifi related tests.
126+
*/
127+
public void wifiTestInit() {
128+
mWifiManager.setWifiEnabled(true);
123129
Log.v(LOG_TAG, "Clear Wifi before we start the test.");
124130
sleep(SHORT_TIMEOUT);
125131
removeConfiguredNetworksAndDisableWifi();
@@ -146,10 +152,10 @@ public void onReceive(Context context, Intent intent) {
146152
Log.v("ConnectivityReceiver", "onReceive() called with " + intent);
147153
return;
148154
}
149-
if (intent.hasExtra(ConnectivityManager.EXTRA_NETWORK_INFO)) {
150-
mNetworkInfo = (NetworkInfo)
151-
intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
152-
}
155+
156+
final ConnectivityManager connManager = (ConnectivityManager) context
157+
.getSystemService(Context.CONNECTIVITY_SERVICE);
158+
mNetworkInfo = connManager.getActiveNetworkInfo();
153159

154160
if (intent.hasExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO)) {
155161
mOtherNetworkInfo = (NetworkInfo)
@@ -525,7 +531,7 @@ public boolean connectToWifi(String knownSSID) {
525531
/**
526532
* Connect to Wi-Fi with the given configuration.
527533
* @param config
528-
* @return true if we ar connected to a given
534+
* @return true if we are connected to a given AP.
529535
*/
530536
public boolean connectToWifiWithConfiguration(WifiConfiguration config) {
531537
// The SSID in the configuration is a pure string, need to convert it to a quoted string.

0 commit comments

Comments
 (0)