From a0a19ea8aa8ed74501a0b0e906796ae0b33b5ea8 Mon Sep 17 00:00:00 2001 From: Irfan Sheriff Date: Wed, 17 Oct 2012 15:21:23 -0700 Subject: [PATCH] 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 --- .../android/net/wifi/cts/WifiManagerTest.java | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) 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 a64477d100..74083015ce 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 @@ public class WifiManagerTest extends AndroidTestCase { } 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); } }