OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "net/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 spdy_stream->SendRequestHeaders(headers.Pass(), NO_MORE_DATA_TO_SEND); | 913 spdy_stream->SendRequestHeaders(headers.Pass(), NO_MORE_DATA_TO_SEND); |
914 | 914 |
915 // Shift time so that a ping will be sent out. | 915 // Shift time so that a ping will be sent out. |
916 g_time_delta = base::TimeDelta::FromSeconds(11); | 916 g_time_delta = base::TimeDelta::FromSeconds(11); |
917 | 917 |
918 data.RunFor(2); | 918 data.RunFor(2); |
919 | 919 |
920 session->CloseSessionOnError(ERR_ABORTED, "Aborting"); | 920 session->CloseSessionOnError(ERR_ABORTED, "Aborting"); |
921 } | 921 } |
922 | 922 |
| 923 TEST_P(SpdySessionTest, StreamIdSpaceExhausted) { |
| 924 const SpdyStreamId kLastStreamId = 0x7fffffff; |
| 925 session_deps_.host_resolver->set_synchronous_mode(true); |
| 926 |
| 927 // Test setup: |stream_hi_water_mark_| and |max_concurrent_streams_| are |
| 928 // fixed to allow for two stream ID assignments, and three concurrent |
| 929 // streams. Four streams are started, and two are activated. Verify the |
| 930 // session goes away, and that the created (but not activated) and |
| 931 // stalled streams are aborted. Also verify the activated streams complete, |
| 932 // at which point the session closes. |
| 933 |
| 934 scoped_ptr<SpdyFrame> req1(spdy_util_.ConstructSpdyGet( |
| 935 NULL, 0, false, kLastStreamId - 2, MEDIUM, true)); |
| 936 scoped_ptr<SpdyFrame> req2( |
| 937 spdy_util_.ConstructSpdyGet(NULL, 0, false, kLastStreamId, MEDIUM, true)); |
| 938 |
| 939 MockWrite writes[] = { |
| 940 CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
| 941 }; |
| 942 |
| 943 scoped_ptr<SpdyFrame> resp1( |
| 944 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, kLastStreamId - 2)); |
| 945 scoped_ptr<SpdyFrame> resp2( |
| 946 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, kLastStreamId)); |
| 947 |
| 948 scoped_ptr<SpdyFrame> body1( |
| 949 spdy_util_.ConstructSpdyBodyFrame(kLastStreamId - 2, true)); |
| 950 scoped_ptr<SpdyFrame> body2( |
| 951 spdy_util_.ConstructSpdyBodyFrame(kLastStreamId, true)); |
| 952 |
| 953 MockRead reads[] = { |
| 954 CreateMockRead(*resp1, 2), CreateMockRead(*resp2, 3), |
| 955 CreateMockRead(*body1, 4), CreateMockRead(*body2, 5), |
| 956 MockRead(ASYNC, 0, 6) // EOF |
| 957 }; |
| 958 |
| 959 DeterministicSocketData data( |
| 960 reads, arraysize(reads), writes, arraysize(writes)); |
| 961 |
| 962 MockConnect connect_data(SYNCHRONOUS, OK); |
| 963 data.set_connect_data(connect_data); |
| 964 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 965 |
| 966 CreateDeterministicNetworkSession(); |
| 967 base::WeakPtr<SpdySession> session = |
| 968 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); |
| 969 |
| 970 // Fix stream_hi_water_mark_ to allow for two stream activations. |
| 971 session->stream_hi_water_mark_ = kLastStreamId - 2; |
| 972 // Fix max_concurrent_streams to allow for three stream creations. |
| 973 session->max_concurrent_streams_ = 3; |
| 974 |
| 975 // Create three streams synchronously, and begin a fourth (which is stalled). |
| 976 GURL url(kDefaultURL); |
| 977 base::WeakPtr<SpdyStream> stream1 = CreateStreamSynchronously( |
| 978 SPDY_REQUEST_RESPONSE_STREAM, session, url, MEDIUM, BoundNetLog()); |
| 979 test::StreamDelegateDoNothing delegate1(stream1); |
| 980 stream1->SetDelegate(&delegate1); |
| 981 |
| 982 base::WeakPtr<SpdyStream> stream2 = CreateStreamSynchronously( |
| 983 SPDY_REQUEST_RESPONSE_STREAM, session, url, MEDIUM, BoundNetLog()); |
| 984 test::StreamDelegateDoNothing delegate2(stream2); |
| 985 stream2->SetDelegate(&delegate2); |
| 986 |
| 987 base::WeakPtr<SpdyStream> stream3 = CreateStreamSynchronously( |
| 988 SPDY_REQUEST_RESPONSE_STREAM, session, url, MEDIUM, BoundNetLog()); |
| 989 test::StreamDelegateDoNothing delegate3(stream3); |
| 990 stream3->SetDelegate(&delegate3); |
| 991 |
| 992 SpdyStreamRequest request4; |
| 993 TestCompletionCallback callback4; |
| 994 EXPECT_EQ(ERR_IO_PENDING, |
| 995 request4.StartRequest(SPDY_REQUEST_RESPONSE_STREAM, |
| 996 session, |
| 997 url, |
| 998 MEDIUM, |
| 999 BoundNetLog(), |
| 1000 callback4.callback())); |
| 1001 |
| 1002 // Streams 1-3 were created. 4th is stalled. No streams are active yet. |
| 1003 EXPECT_EQ(0u, session->num_active_streams()); |
| 1004 EXPECT_EQ(3u, session->num_created_streams()); |
| 1005 EXPECT_EQ(1u, session->pending_create_stream_queue_size(MEDIUM)); |
| 1006 |
| 1007 // Activate stream 1. One ID remains available. |
| 1008 stream1->SendRequestHeaders( |
| 1009 scoped_ptr<SpdyHeaderBlock>( |
| 1010 spdy_util_.ConstructGetHeaderBlock(url.spec())), |
| 1011 NO_MORE_DATA_TO_SEND); |
| 1012 data.RunFor(1); |
| 1013 |
| 1014 EXPECT_EQ(kLastStreamId - 2u, stream1->stream_id()); |
| 1015 EXPECT_EQ(1u, session->num_active_streams()); |
| 1016 EXPECT_EQ(2u, session->num_created_streams()); |
| 1017 EXPECT_EQ(1u, session->pending_create_stream_queue_size(MEDIUM)); |
| 1018 |
| 1019 // Activate stream 2. ID space is exhausted. |
| 1020 stream2->SendRequestHeaders( |
| 1021 scoped_ptr<SpdyHeaderBlock>( |
| 1022 spdy_util_.ConstructGetHeaderBlock(url.spec())), |
| 1023 NO_MORE_DATA_TO_SEND); |
| 1024 data.RunFor(1); |
| 1025 |
| 1026 // Active streams remain active. |
| 1027 EXPECT_EQ(kLastStreamId, stream2->stream_id()); |
| 1028 EXPECT_EQ(2u, session->num_active_streams()); |
| 1029 |
| 1030 // Session is going away. Created and stalled streams were aborted. |
| 1031 EXPECT_EQ(SpdySession::STATE_GOING_AWAY, session->availability_state_); |
| 1032 EXPECT_EQ(ERR_ABORTED, delegate3.WaitForClose()); |
| 1033 EXPECT_EQ(ERR_ABORTED, callback4.WaitForResult()); |
| 1034 EXPECT_EQ(0u, session->num_created_streams()); |
| 1035 EXPECT_EQ(0u, session->pending_create_stream_queue_size(MEDIUM)); |
| 1036 |
| 1037 // Read responses on remaining active streams. |
| 1038 data.RunFor(4); |
| 1039 EXPECT_EQ(OK, delegate1.WaitForClose()); |
| 1040 EXPECT_EQ(kUploadData, delegate1.TakeReceivedData()); |
| 1041 EXPECT_EQ(OK, delegate2.WaitForClose()); |
| 1042 EXPECT_EQ(kUploadData, delegate2.TakeReceivedData()); |
| 1043 |
| 1044 // Session was destroyed. |
| 1045 EXPECT_FALSE(session.get()); |
| 1046 } |
| 1047 |
923 TEST_P(SpdySessionTest, DeleteExpiredPushStreams) { | 1048 TEST_P(SpdySessionTest, DeleteExpiredPushStreams) { |
924 session_deps_.host_resolver->set_synchronous_mode(true); | 1049 session_deps_.host_resolver->set_synchronous_mode(true); |
925 session_deps_.time_func = TheNearFuture; | 1050 session_deps_.time_func = TheNearFuture; |
926 | 1051 |
927 scoped_ptr<SpdyFrame> req( | 1052 scoped_ptr<SpdyFrame> req( |
928 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); | 1053 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); |
929 scoped_ptr<SpdyFrame> rst( | 1054 scoped_ptr<SpdyFrame> rst( |
930 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); | 1055 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
931 | 1056 |
932 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( | 1057 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( |
(...skipping 3204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4137 RST_STREAM_PROTOCOL_ERROR)); | 4262 RST_STREAM_PROTOCOL_ERROR)); |
4138 CHECK_EQ(STATUS_CODE_FRAME_SIZE_ERROR, | 4263 CHECK_EQ(STATUS_CODE_FRAME_SIZE_ERROR, |
4139 MapRstStreamStatusToProtocolError( | 4264 MapRstStreamStatusToProtocolError( |
4140 RST_STREAM_FRAME_SIZE_ERROR)); | 4265 RST_STREAM_FRAME_SIZE_ERROR)); |
4141 CHECK_EQ(STATUS_CODE_ENHANCE_YOUR_CALM, | 4266 CHECK_EQ(STATUS_CODE_ENHANCE_YOUR_CALM, |
4142 MapRstStreamStatusToProtocolError( | 4267 MapRstStreamStatusToProtocolError( |
4143 RST_STREAM_ENHANCE_YOUR_CALM)); | 4268 RST_STREAM_ENHANCE_YOUR_CALM)); |
4144 } | 4269 } |
4145 | 4270 |
4146 } // namespace net | 4271 } // namespace net |
OLD | NEW |