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

Unified Diff: components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java

Issue 1999303002: Fix flaky NQE cronet test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add locks so that counts can be read concurrently Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java
index f79e4116ed30e0d559f315583e007aa41c5f6261..95f35eed336afe712c640f82540cbb353600e2fb 100644
--- a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java
@@ -29,6 +29,7 @@ import java.util.HashSet;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
/**
* Test CronetEngine.
@@ -126,25 +127,43 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
static class TestNetworkQualityListener
implements NetworkQualityRttListener, NetworkQualityThroughputListener {
- int mRttObservationCount;
- int mThroughputObservationCount;
+ // Lock to ensure that observation counts can be updated and read by different threads.
+ private final Object mLock = new Object();
+ private final ConditionVariable mWaitForThroughput;
+ private int mRttObservationCount;
+ private int mThroughputObservationCount;
+
+ TestNetworkQualityListener(ConditionVariable waitForThroughput) {
+ mWaitForThroughput = waitForThroughput;
+ }
@Override
public void onRttObservation(int rttMs, long when, int source) {
- mRttObservationCount++;
+ synchronized (mLock) {
+ mRttObservationCount++;
+ }
}
@Override
public void onThroughputObservation(int throughputKbps, long when, int source) {
- mThroughputObservationCount++;
+ synchronized (mLock) {
+ if (mWaitForThroughput != null) {
+ mWaitForThroughput.open();
+ }
+ mThroughputObservationCount++;
+ }
}
public int rttObservationCount() {
- return mRttObservationCount;
+ synchronized (mLock) {
+ return mRttObservationCount;
+ }
}
public int throughputObservationCount() {
- return mThroughputObservationCount;
+ synchronized (mLock) {
+ return mThroughputObservationCount;
+ }
}
}
@@ -220,11 +239,9 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
@SmallTest
@Feature({"Cronet"})
- // TODO(xunjieli): Remove annotation after crbug.com/539519 is fixed.
- @SuppressWarnings("deprecation")
public void testRealTimeNetworkQualityObservationsNotEnabled() throws Exception {
mTestFramework = startCronetTestFramework();
- TestNetworkQualityListener networkQualityListener = new TestNetworkQualityListener();
+ TestNetworkQualityListener networkQualityListener = new TestNetworkQualityListener(null);
try {
mTestFramework.mCronetEngine.addRttListener(networkQualityListener);
fail("Should throw an exception.");
@@ -247,12 +264,10 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
@SmallTest
@Feature({"Cronet"})
- // TODO(xunjieli): Remove annotation after crbug.com/539519 is fixed.
- @SuppressWarnings("deprecation")
public void testRealTimeNetworkQualityObservationsListenerRemoved() throws Exception {
mTestFramework = startCronetTestFramework();
TestExecutor testExecutor = new TestExecutor();
- TestNetworkQualityListener networkQualityListener = new TestNetworkQualityListener();
+ TestNetworkQualityListener networkQualityListener = new TestNetworkQualityListener(null);
mTestFramework.mCronetEngine.enableNetworkQualityEstimatorForTesting(
true, true, testExecutor);
mTestFramework.mCronetEngine.addRttListener(networkQualityListener);
@@ -270,19 +285,15 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
mTestFramework.mCronetEngine.shutdown();
}
- /*
@SmallTest
@Feature({"Cronet"})
- // TODO(xunjieli): Remove annotation after crbug.com/539519 is fixed.
- @SuppressWarnings("deprecation")
- */
- @FlakyTest(message = "http://crbug.com/614227")
public void testRealTimeNetworkQualityObservations() throws Exception {
mTestFramework = startCronetTestFramework();
- TestExecutor testExecutor = new TestExecutor();
- TestNetworkQualityListener networkQualityListener = new TestNetworkQualityListener();
- mTestFramework.mCronetEngine.enableNetworkQualityEstimatorForTesting(
- true, true, testExecutor);
+ Executor executor = Executors.newSingleThreadExecutor();
+ ConditionVariable waitForThroughput = new ConditionVariable();
+ TestNetworkQualityListener networkQualityListener =
+ new TestNetworkQualityListener(waitForThroughput);
+ mTestFramework.mCronetEngine.enableNetworkQualityEstimatorForTesting(true, true, executor);
mTestFramework.mCronetEngine.addRttListener(networkQualityListener);
mTestFramework.mCronetEngine.addThroughputListener(networkQualityListener);
TestUrlRequestCallback callback = new TestUrlRequestCallback();
@@ -290,9 +301,17 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
mTestFramework.mCronetEngine.createRequest(mUrl, callback, callback.getExecutor());
urlRequest.start();
callback.blockForDone();
- testExecutor.runAllTasks();
- assertTrue(networkQualityListener.rttObservationCount() > 0);
+
+ // Throughput observation is posted to the network quality estimator on the network thread
+ // after the UrlRequest is completed. The observations are then eventually posted to
+ // throughput listeners on the executor provided to network quality.
+ waitForThroughput.block();
assertTrue(networkQualityListener.throughputObservationCount() > 0);
+
+ // Check RTT observation count after throughput observation has been received. This ensures
+ // that executor has finished posting the RTT observation to the RTT listeners.
+ assertTrue(networkQualityListener.rttObservationCount() > 0);
+
mTestFramework.mCronetEngine.shutdown();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698