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

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

Issue 1815163003: Fix BidirectionalStreamTest#testFailures flake (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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; 7 import android.os.ConditionVariable;
8 import android.test.suitebuilder.annotation.SmallTest; 8 import android.test.suitebuilder.annotation.SmallTest;
9 9
10 import org.chromium.base.test.util.DisabledTest; 10 import org.chromium.base.test.util.DisabledTest;
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 // Finish the stream with a direct ByteBuffer. 805 // Finish the stream with a direct ByteBuffer.
806 callback.setAutoAdvance(true); 806 callback.setAutoAdvance(true);
807 ByteBuffer readBuffer = ByteBuffer.allocateDirect(5); 807 ByteBuffer readBuffer = ByteBuffer.allocateDirect(5);
808 stream.read(readBuffer); 808 stream.read(readBuffer);
809 callback.blockForDone(); 809 callback.blockForDone();
810 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 810 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
811 assertEquals("GET", callback.mResponseAsString); 811 assertEquals("GET", callback.mResponseAsString);
812 } 812 }
813 813
814 private void throwOrCancel(FailureType failureType, ResponseStep failureStep , 814 private void throwOrCancel(FailureType failureType, ResponseStep failureStep ,
815 boolean expectResponseInfo, boolean expectError) { 815 boolean expectResponseInfo, boolean expectError) {
mef 2016/03/18 15:30:18 remove |expectResponseInfo|.
xunjieli 2016/03/18 15:39:47 Done.
816 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa llback(); 816 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa llback();
817 callback.setFailure(failureType, failureStep); 817 callback.setFailure(failureType, failureStep);
818 BidirectionalStream.Builder builder = 818 BidirectionalStream.Builder builder =
819 new BidirectionalStream.Builder(Http2TestServer.getEchoMethodUrl (), callback, 819 new BidirectionalStream.Builder(Http2TestServer.getEchoMethodUrl (), callback,
820 callback.getExecutor(), mTestFramework.mCronetEngine); 820 callback.getExecutor(), mTestFramework.mCronetEngine);
821 BidirectionalStream stream = builder.setHttpMethod("GET").build(); 821 BidirectionalStream stream = builder.setHttpMethod("GET").build();
822 stream.start(); 822 stream.start();
823 callback.blockForDone(); 823 callback.blockForDone();
824 // assertEquals(callback.mResponseStep, failureStep); 824 // assertEquals(callback.mResponseStep, failureStep);
825 assertTrue(stream.isDone()); 825 assertTrue(stream.isDone());
826 assertEquals(expectResponseInfo, callback.mResponseInfo != null); 826 // Cancellation when request headers are sent does not guarantee that
827 // mResponseInfo is null because there might be a
828 // onResponseHeadersReceived already queued in the executor.
829 // See crbug.com/594432.
830 if (failureStep != ResponseStep.ON_REQUEST_HEADERS_SENT) {
831 assertNotNull(callback.mResponseInfo);
832 }
827 assertEquals(expectError, callback.mError != null); 833 assertEquals(expectError, callback.mError != null);
828 assertEquals(expectError, callback.mOnErrorCalled); 834 assertEquals(expectError, callback.mOnErrorCalled);
829 assertEquals(failureType == FailureType.CANCEL_SYNC 835 assertEquals(failureType == FailureType.CANCEL_SYNC
830 || failureType == FailureType.CANCEL_ASYNC 836 || failureType == FailureType.CANCEL_ASYNC
831 || failureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE , 837 || failureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE ,
832 callback.mOnCanceledCalled); 838 callback.mOnCanceledCalled);
833 } 839 }
834 840
835 @SmallTest 841 @SmallTest
836 @Feature({"Cronet"}) 842 @Feature({"Cronet"})
837 @OnlyRunNativeCronet 843 @OnlyRunNativeCronet
838 public void testFailures() throws Exception { 844 public void testFailures() throws Exception {
839 throwOrCancel(FailureType.CANCEL_SYNC, ResponseStep.ON_REQUEST_HEADERS_S ENT, false, false); 845 throwOrCancel(FailureType.CANCEL_SYNC, ResponseStep.ON_REQUEST_HEADERS_S ENT, false);
840 throwOrCancel(FailureType.CANCEL_ASYNC, ResponseStep.ON_REQUEST_HEADERS_ SENT, false, false); 846 throwOrCancel(FailureType.CANCEL_ASYNC, ResponseStep.ON_REQUEST_HEADERS_ SENT, false);
841 throwOrCancel(FailureType.CANCEL_ASYNC_WITHOUT_PAUSE, ResponseStep.ON_RE QUEST_HEADERS_SENT, 847 throwOrCancel(FailureType.CANCEL_ASYNC_WITHOUT_PAUSE, ResponseStep.ON_RE QUEST_HEADERS_SENT,
842 false, false); 848 false);
843 throwOrCancel(FailureType.THROW_SYNC, ResponseStep.ON_REQUEST_HEADERS_SE NT, false, true); 849 throwOrCancel(FailureType.THROW_SYNC, ResponseStep.ON_REQUEST_HEADERS_SE NT, true);
844 850
845 throwOrCancel(FailureType.CANCEL_SYNC, ResponseStep.ON_RESPONSE_STARTED, true, false); 851 throwOrCancel(FailureType.CANCEL_SYNC, ResponseStep.ON_RESPONSE_STARTED, false);
846 throwOrCancel(FailureType.CANCEL_ASYNC, ResponseStep.ON_RESPONSE_STARTED , true, false); 852 throwOrCancel(FailureType.CANCEL_ASYNC, ResponseStep.ON_RESPONSE_STARTED , false);
847 throwOrCancel(FailureType.CANCEL_ASYNC_WITHOUT_PAUSE, ResponseStep.ON_RE SPONSE_STARTED, 853 throwOrCancel(
848 true, false); 854 FailureType.CANCEL_ASYNC_WITHOUT_PAUSE, ResponseStep.ON_RESPONSE _STARTED, false);
849 throwOrCancel(FailureType.THROW_SYNC, ResponseStep.ON_RESPONSE_STARTED, true, true); 855 throwOrCancel(FailureType.THROW_SYNC, ResponseStep.ON_RESPONSE_STARTED, true);
850 856
851 throwOrCancel(FailureType.CANCEL_SYNC, ResponseStep.ON_READ_COMPLETED, t rue, false); 857 throwOrCancel(FailureType.CANCEL_SYNC, ResponseStep.ON_READ_COMPLETED, f alse);
852 throwOrCancel(FailureType.CANCEL_ASYNC, ResponseStep.ON_READ_COMPLETED, true, false); 858 throwOrCancel(FailureType.CANCEL_ASYNC, ResponseStep.ON_READ_COMPLETED, false);
853 throwOrCancel(FailureType.CANCEL_ASYNC_WITHOUT_PAUSE, ResponseStep.ON_RE AD_COMPLETED, true, 859 throwOrCancel(
854 false); 860 FailureType.CANCEL_ASYNC_WITHOUT_PAUSE, ResponseStep.ON_READ_COM PLETED, false);
855 throwOrCancel(FailureType.THROW_SYNC, ResponseStep.ON_READ_COMPLETED, tr ue, true); 861 throwOrCancel(FailureType.THROW_SYNC, ResponseStep.ON_READ_COMPLETED, tr ue);
856 } 862 }
857 863
858 @SmallTest 864 @SmallTest
859 @Feature({"Cronet"}) 865 @Feature({"Cronet"})
860 @OnlyRunNativeCronet 866 @OnlyRunNativeCronet
861 public void testThrowOnSucceeded() { 867 public void testThrowOnSucceeded() {
862 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa llback(); 868 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa llback();
863 callback.setFailure(FailureType.THROW_SYNC, ResponseStep.ON_SUCCEEDED); 869 callback.setFailure(FailureType.THROW_SYNC, ResponseStep.ON_SUCCEEDED);
864 BidirectionalStream.Builder builder = 870 BidirectionalStream.Builder builder =
865 new BidirectionalStream.Builder(Http2TestServer.getEchoMethodUrl (), callback, 871 new BidirectionalStream.Builder(Http2TestServer.getEchoMethodUrl (), callback,
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 private static String bufferContentsToString(ByteBuffer byteBuffer, int star t, int end) { 1050 private static String bufferContentsToString(ByteBuffer byteBuffer, int star t, int end) {
1045 // Use a duplicate to avoid modifying byteBuffer. 1051 // Use a duplicate to avoid modifying byteBuffer.
1046 ByteBuffer duplicate = byteBuffer.duplicate(); 1052 ByteBuffer duplicate = byteBuffer.duplicate();
1047 duplicate.position(start); 1053 duplicate.position(start);
1048 duplicate.limit(end); 1054 duplicate.limit(end);
1049 byte[] contents = new byte[duplicate.remaining()]; 1055 byte[] contents = new byte[duplicate.remaining()];
1050 duplicate.get(contents); 1056 duplicate.get(contents);
1051 return new String(contents); 1057 return new String(contents);
1052 } 1058 }
1053 } 1059 }
OLDNEW
« 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