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

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

Issue 2506653003: Instrument CronetUrlRequestTest#testThrowOrCancelInOnCanceled flaky test (Closed)
Patch Set: Created 4 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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; 7 import android.os.ConditionVariable;
8 import android.os.StrictMode; 8 import android.os.StrictMode;
9 import android.test.MoreAsserts; 9 import android.test.MoreAsserts;
10 import android.test.suitebuilder.annotation.SmallTest; 10 import android.test.suitebuilder.annotation.SmallTest;
(...skipping 1648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 callback.setFailure(failureType, failureStep); 1659 callback.setFailure(failureType, failureStep);
1660 UrlRequest.Builder builder = mTestFramework.mCronetEngine.newUrlRequestB uilder( 1660 UrlRequest.Builder builder = mTestFramework.mCronetEngine.newUrlRequestB uilder(
1661 NativeTestServer.getRedirectURL(), callback, callback.getExecuto r()); 1661 NativeTestServer.getRedirectURL(), callback, callback.getExecuto r());
1662 UrlRequest urlRequest = builder.build(); 1662 UrlRequest urlRequest = builder.build();
1663 urlRequest.start(); 1663 urlRequest.start();
1664 callback.blockForDone(); 1664 callback.blockForDone();
1665 // Wait for all posted tasks to be executed to ensure there is no unhand led exception. 1665 // Wait for all posted tasks to be executed to ensure there is no unhand led exception.
1666 callback.shutdownExecutorAndWait(); 1666 callback.shutdownExecutorAndWait();
1667 assertEquals(1, callback.mRedirectCount); 1667 assertEquals(1, callback.mRedirectCount);
1668 if (failureType == FailureType.CANCEL_SYNC || failureType == FailureType .CANCEL_ASYNC) { 1668 if (failureType == FailureType.CANCEL_SYNC || failureType == FailureType .CANCEL_ASYNC) {
1669 assertEquals(ResponseStep.ON_CANCELED, callback.mResponseStep); 1669 assertResponseStepCancelled(callback);
1670 } else if (failureType == FailureType.THROW_SYNC) { 1670 } else if (failureType == FailureType.THROW_SYNC) {
1671 assertEquals(ResponseStep.ON_FAILED, callback.mResponseStep); 1671 assertEquals(ResponseStep.ON_FAILED, callback.mResponseStep);
1672 } 1672 }
1673 assertTrue(urlRequest.isDone()); 1673 assertTrue(urlRequest.isDone());
1674 assertEquals(expectResponseInfo, callback.mResponseInfo != null); 1674 assertEquals(expectResponseInfo, callback.mResponseInfo != null);
1675 assertEquals(expectError, callback.mError != null); 1675 assertEquals(expectError, callback.mError != null);
1676 assertEquals(expectError, callback.mOnErrorCalled); 1676 assertEquals(expectError, callback.mOnErrorCalled);
1677 assertEquals(failureType == FailureType.CANCEL_SYNC 1677 assertEquals(failureType == FailureType.CANCEL_SYNC
1678 || failureType == FailureType.CANCEL_ASYNC 1678 || failureType == FailureType.CANCEL_ASYNC
1679 || failureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE , 1679 || failureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE ,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1777 } 1777 }
1778 }; 1778 };
1779 callback.setFailure(type, ResponseStep.ON_CANCELED); 1779 callback.setFailure(type, ResponseStep.ON_CANCELED);
1780 UrlRequest.Builder builder = mTestFramework.mCronetEngine.newUrlRequ estBuilder( 1780 UrlRequest.Builder builder = mTestFramework.mCronetEngine.newUrlRequ estBuilder(
1781 NativeTestServer.getEchoBodyURL(), callback, callback.getExe cutor()); 1781 NativeTestServer.getEchoBodyURL(), callback, callback.getExe cutor());
1782 UrlRequest urlRequest = builder.build(); 1782 UrlRequest urlRequest = builder.build();
1783 urlRequest.start(); 1783 urlRequest.start();
1784 callback.blockForDone(); 1784 callback.blockForDone();
1785 // Wait for all posted tasks to be executed to ensure there is no un handled exception. 1785 // Wait for all posted tasks to be executed to ensure there is no un handled exception.
1786 callback.shutdownExecutorAndWait(); 1786 callback.shutdownExecutorAndWait();
1787 assertEquals(ResponseStep.ON_CANCELED, callback.mResponseStep); 1787 assertResponseStepCancelled(callback);
1788 assertTrue(urlRequest.isDone()); 1788 assertTrue(urlRequest.isDone());
1789 assertNotNull(callback.mResponseInfo); 1789 assertNotNull(callback.mResponseInfo);
1790 assertNull(callback.mError); 1790 assertNull(callback.mError);
1791 assertTrue(callback.mOnCanceledCalled); 1791 assertTrue(callback.mOnCanceledCalled);
1792 } 1792 }
1793 } 1793 }
1794 1794
1795 @SmallTest 1795 @SmallTest
1796 @Feature({"Cronet"}) 1796 @Feature({"Cronet"})
1797 @OnlyRunNativeCronet // No destroyed callback for tests 1797 @OnlyRunNativeCronet // No destroyed callback for tests
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 // as a String. Does not modify byteBuffer's position(). 2004 // as a String. Does not modify byteBuffer's position().
2005 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int end) { 2005 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int end) {
2006 // Use a duplicate to avoid modifying byteBuffer. 2006 // Use a duplicate to avoid modifying byteBuffer.
2007 ByteBuffer duplicate = byteBuffer.duplicate(); 2007 ByteBuffer duplicate = byteBuffer.duplicate();
2008 duplicate.position(start); 2008 duplicate.position(start);
2009 duplicate.limit(end); 2009 duplicate.limit(end);
2010 byte[] contents = new byte[duplicate.remaining()]; 2010 byte[] contents = new byte[duplicate.remaining()];
2011 duplicate.get(contents); 2011 duplicate.get(contents);
2012 return new String(contents); 2012 return new String(contents);
2013 } 2013 }
2014
2015 private void assertResponseStepCancelled(TestUrlRequestCallback callback) {
2016 String message = "Unexpected response state " + callback.mResponseStep;
Charles 2016/11/15 19:08:16 A more idiomatic way to show this would be to say
kapishnikov 2016/11/15 21:17:01 Done. The AssertionError with cause was only intro
Charles 2016/11/15 21:38:22 I think you may need to upload a new patchset
kapishnikov 2016/11/15 21:49:17 Because the call to the supertype constructor shou
Charles 2016/11/15 22:29:33 That's true, but if you make this logic a private
2017 if (callback.mError != null) {
2018 message += message + ". Recorded error: " + callback.mError;
2019 }
2020 assertEquals(message, ResponseStep.ON_CANCELED, callback.mResponseStep);
2021 }
2014 } 2022 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698