Make packet count test more robust
Ensure the packet count test does not fail due to a single attempt.
Our goal is to just ensure the packet count API exists.
Bug: 7001746
Change-Id: I8c6604528946166969126cd5b085024f81790a77
diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java
index a64477d..7408301 100644
--- a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java
+++ b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java
@@ -399,30 +399,39 @@
}
assertTrue(mWifiManager.isWifiEnabled());
- // Wait for a WiFi connection
- connectWifi();
+ int i = 0;
+ for (; i < 15; i++) {
+ // Wait for a WiFi connection
+ connectWifi();
- // Read TX packet counter
- int txcount1 = getTxPacketCount();
+ // Read TX packet counter
+ int txcount1 = getTxPacketCount();
- // Do some network operations
- HttpURLConnection connection = null;
- try {
- URL url = new URL("http://www.google.com/");
- connection = (HttpURLConnection) url.openConnection();
- connection.setInstanceFollowRedirects(false);
- connection.setConnectTimeout(TIMEOUT_MSEC);
- connection.setReadTimeout(TIMEOUT_MSEC);
- connection.setUseCaches(false);
- connection.getInputStream();
- } catch (Exception e) {
- // ignore
- } finally {
- if (connection != null) connection.disconnect();
+ // Do some network operations
+ HttpURLConnection connection = null;
+ try {
+ URL url = new URL("http://www.google.com/");
+ connection = (HttpURLConnection) url.openConnection();
+ connection.setInstanceFollowRedirects(false);
+ connection.setConnectTimeout(TIMEOUT_MSEC);
+ connection.setReadTimeout(TIMEOUT_MSEC);
+ connection.setUseCaches(false);
+ connection.getInputStream();
+ } catch (Exception e) {
+ // ignore
+ } finally {
+ if (connection != null) connection.disconnect();
+ }
+
+ // Read TX packet counter again and make sure it increases
+ int txcount2 = getTxPacketCount();
+
+ if (txcount2 > txcount1) {
+ break;
+ } else {
+ Thread.sleep(DURATION);
+ }
}
-
- // Read TX packet counter again and make sure it increases
- int txcount2 = getTxPacketCount();
- assertTrue(txcount2 > txcount1);
+ assertTrue(i < 15);
}
}