Read all response to generate enough traffic while testing
Currently, testUidTagStateDetails relies on the test URL return
enough data (~100k) to ensure untagged traffic is not too much
to cause flaky. But aosp/2575590 change it to read only first few
bytes to speed up the test which would break this assumption.
Thus in this change:
1. Revert partical changes of aosp/2575590
2. Use BufferedInputStream to speed up test instead, which speed up
testUidTagStateDetails from 2032ms to 902ms in local trials.
Test: atest CtsNetTestCases:NetworkStatsManagerTest
Bug: 289112440
Change-Id: I1b32d9e069a7b10664065e138c75c6bfe7928f23
diff --git a/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java b/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java
index d8a0b07..d70f605 100644
--- a/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java
+++ b/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java
@@ -82,9 +82,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;
+import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.UnknownHostException;
@@ -220,7 +220,7 @@
} else {
Log.w(LOG_TAG, "Network: " + networkInfo.toString());
}
- InputStreamReader in = null;
+ BufferedInputStream in = null;
HttpURLConnection urlc = null;
String originalKeepAlive = System.getProperty("http.keepAlive");
System.setProperty("http.keepAlive", "false");
@@ -236,10 +236,10 @@
urlc.connect();
boolean ping = urlc.getResponseCode() == 200;
if (ping) {
- in = new InputStreamReader((InputStream) urlc.getContent());
- // Since the test doesn't really care about the precise amount of data, instead
- // of reading all contents, just read few bytes at the beginning.
- in.read();
+ in = new BufferedInputStream((InputStream) urlc.getContent());
+ while (in.read() != -1) {
+ // Comments to suppress lint error.
+ }
}
} catch (Exception e) {
Log.i(LOG_TAG, "Badness during exercising remote server: " + e);