Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: components/cronet/android/test/javatests/src/org/chromium/net/QuicTest.java

Issue 2852153002: Fix flaky NQE QUIC test (Closed)
Patch Set: pauljensen comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import android.os.ConditionVariable;
8 import android.support.test.filters.LargeTest; 7 import android.support.test.filters.LargeTest;
9 import android.support.test.filters.SmallTest; 8 import android.support.test.filters.SmallTest;
10 9
11 import org.json.JSONObject; 10 import org.json.JSONObject;
12 11
13 import org.chromium.base.Log; 12 import org.chromium.base.Log;
14 import org.chromium.base.annotations.SuppressFBWarnings; 13 import org.chromium.base.annotations.SuppressFBWarnings;
15 import org.chromium.base.test.util.Feature; 14 import org.chromium.base.test.util.Feature;
16 import org.chromium.net.CronetTestBase.OnlyRunNativeCronet; 15 import org.chromium.net.CronetTestBase.OnlyRunNativeCronet;
17 import org.chromium.net.MetricsTestUtil.TestRequestFinishedListener; 16 import org.chromium.net.MetricsTestUtil.TestRequestFinishedListener;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 private boolean fileContainsString(String filename, String content) throws I OException { 141 private boolean fileContainsString(String filename, String content) throws I OException {
143 File file = 142 File file =
144 new File(CronetTestFramework.getTestStorage(getContext()) + "/pr efs/" + filename); 143 new File(CronetTestFramework.getTestStorage(getContext()) + "/pr efs/" + filename);
145 FileInputStream fileInputStream = new FileInputStream(file); 144 FileInputStream fileInputStream = new FileInputStream(file);
146 byte[] data = new byte[(int) file.length()]; 145 byte[] data = new byte[(int) file.length()];
147 fileInputStream.read(data); 146 fileInputStream.read(data);
148 fileInputStream.close(); 147 fileInputStream.close();
149 return new String(data, "UTF-8").contains(content); 148 return new String(data, "UTF-8").contains(content);
150 } 149 }
151 150
151 /**
152 * Tests that the network quality listeners are propoerly notified when QUIC is enabled.
153 */
152 @LargeTest 154 @LargeTest
153 @Feature({"Cronet"}) 155 @Feature({"Cronet"})
154 @OnlyRunNativeCronet 156 @OnlyRunNativeCronet
155 @SuppressWarnings("deprecation") 157 @SuppressWarnings("deprecation")
156 public void testRealTimeNetworkQualityObservationsWithQuic() throws Exceptio n { 158 public void testNQEWithQuic() throws Exception {
157 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, mBuilder); 159 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, mBuilder);
158 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 160 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
159 ConditionVariable waitForThroughput = new ConditionVariable();
160 161
161 TestNetworkQualityRttListener rttListener = 162 TestNetworkQualityRttListener rttListener =
162 new TestNetworkQualityRttListener(Executors.newSingleThreadExecu tor()); 163 new TestNetworkQualityRttListener(Executors.newSingleThreadExecu tor());
163 TestNetworkQualityThroughputListener throughputListener = 164 TestNetworkQualityThroughputListener throughputListener =
164 new TestNetworkQualityThroughputListener( 165 new TestNetworkQualityThroughputListener(Executors.newSingleThre adExecutor());
165 Executors.newSingleThreadExecutor(), waitForThroughput);
166 166
167 mTestFramework.mCronetEngine.addRttListener(rttListener); 167 mTestFramework.mCronetEngine.addRttListener(rttListener);
168 mTestFramework.mCronetEngine.addThroughputListener(throughputListener); 168 mTestFramework.mCronetEngine.addThroughputListener(throughputListener);
169 169
170 mTestFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting( true, true, true); 170 mTestFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting( true, true, true);
171 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 171 TestUrlRequestCallback callback = new TestUrlRequestCallback();
172 172
173 // Although the native stack races QUIC and SPDY for the first request, 173 // Although the native stack races QUIC and SPDY for the first request,
174 // since there is no http server running on the corresponding TCP port, 174 // since there is no http server running on the corresponding TCP port,
175 // QUIC will always succeed with a 200 (see 175 // QUIC will always succeed with a 200 (see
176 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 176 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
177 UrlRequest.Builder requestBuilder = mTestFramework.mCronetEngine.newUrlR equestBuilder( 177 UrlRequest.Builder requestBuilder = mTestFramework.mCronetEngine.newUrlR equestBuilder(
178 quicURL, callback, callback.getExecutor()); 178 quicURL, callback, callback.getExecutor());
179 requestBuilder.build().start(); 179 requestBuilder.build().start();
180 callback.blockForDone(); 180 callback.blockForDone();
181 181
182 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 182 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
183 String expectedContent = "This is a simple text file served by QUIC.\n"; 183 String expectedContent = "This is a simple text file served by QUIC.\n";
184 assertEquals(expectedContent, callback.mResponseAsString); 184 assertEquals(expectedContent, callback.mResponseAsString);
185 assertIsQuic(callback.mResponseInfo); 185 assertIsQuic(callback.mResponseInfo);
186 186
187 // Throughput observation is posted to the network quality estimator on the network thread 187 // Throughput observation is posted to the network quality estimator on the network thread
188 // after the UrlRequest is completed. The observations are then eventual ly posted to 188 // after the UrlRequest is completed. The observations are then eventual ly posted to
189 // throughput listeners on the executor provided to network quality. 189 // throughput listeners on the executor provided to network quality.
190 waitForThroughput.block(); 190 throughputListener.waitUntilFirstThroughputObservationReceived();
191
192 // Wait for RTT observation (at the URL request layer) to be posted.
193 rttListener.waitUntilFirstUrlRequestRTTReceived();
194
191 assertTrue(throughputListener.throughputObservationCount() > 0); 195 assertTrue(throughputListener.throughputObservationCount() > 0);
192 196
193 // Check RTT observation count after throughput observation has been rec eived. This ensures 197 // Check RTT observation count after throughput observation has been rec eived. This ensures
194 // that executor has finished posting the RTT observation to the RTT lis teners. 198 // that executor has finished posting the RTT observation to the RTT lis teners.
195 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST 199 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST
196 assertTrue(rttListener.rttObservationCount(0) > 0); 200 assertTrue(rttListener.rttObservationCount(0) > 0);
197 201
198 // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC 202 // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC
199 assertTrue(rttListener.rttObservationCount(2) > 0); 203 assertTrue(rttListener.rttObservationCount(2) > 0);
200 204
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 MetricsTestUtil.checkNoConnectTiming(requestInfo.getMetrics()); 277 MetricsTestUtil.checkNoConnectTiming(requestInfo.getMetrics());
274 278
275 mTestFramework.mCronetEngine.shutdown(); 279 mTestFramework.mCronetEngine.shutdown();
276 } 280 }
277 281
278 // Helper method to assert that the request is negotiated over QUIC. 282 // Helper method to assert that the request is negotiated over QUIC.
279 private void assertIsQuic(UrlResponseInfo responseInfo) { 283 private void assertIsQuic(UrlResponseInfo responseInfo) {
280 assertTrue(responseInfo.getNegotiatedProtocol().startsWith(QUIC_PROTOCOL _STRING_PREFIX)); 284 assertTrue(responseInfo.getNegotiatedProtocol().startsWith(QUIC_PROTOCOL _STRING_PREFIX));
281 } 285 }
282 } 286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698