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

Side by Side Diff: net/tools/quic/quic_epoll_connection_helper_test.cc

Issue 23597045: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged QuicPriority to RequestPriority changes Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
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/tools/quic/quic_epoll_connection_helper.h" 5 #include "net/tools/quic/quic_epoll_connection_helper.h"
6 6
7 #include "net/quic/crypto/crypto_protocol.h" 7 #include "net/quic/crypto/crypto_protocol.h"
8 #include "net/quic/crypto/quic_decrypter.h" 8 #include "net/quic/crypto/quic_decrypter.h"
9 #include "net/quic/crypto/quic_encrypter.h" 9 #include "net/quic/crypto/quic_encrypter.h"
10 #include "net/quic/crypto/quic_random.h" 10 #include "net/quic/crypto/quic_random.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 frame1_(1, false, 0, data1) { 84 frame1_(1, false, 0, data1) {
85 connection_.set_visitor(&visitor_); 85 connection_.set_visitor(&visitor_);
86 connection_.SetSendAlgorithm(send_algorithm_); 86 connection_.SetSendAlgorithm(send_algorithm_);
87 epoll_server_.set_timeout_in_us(-1); 87 epoll_server_.set_timeout_in_us(-1);
88 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _, _)). 88 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _, _)).
89 WillRepeatedly(Return(QuicTime::Delta::Zero())); 89 WillRepeatedly(Return(QuicTime::Delta::Zero()));
90 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return( 90 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return(
91 QuicBandwidth::FromKBitsPerSecond(100))); 91 QuicBandwidth::FromKBitsPerSecond(100)));
92 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(Return( 92 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(Return(
93 QuicTime::Delta::FromMilliseconds(100))); 93 QuicTime::Delta::FromMilliseconds(100)));
94 ON_CALL(*send_algorithm_, SentPacket(_, _, _, _, _))
95 .WillByDefault(Return(true));
94 } 96 }
95 97
96 QuicPacket* ConstructDataPacket(QuicPacketSequenceNumber number, 98 QuicPacket* ConstructDataPacket(QuicPacketSequenceNumber number,
97 QuicFecGroupNumber fec_group) { 99 QuicFecGroupNumber fec_group) {
98 header_.public_header.version_flag = false; 100 header_.public_header.version_flag = false;
99 header_.public_header.reset_flag = false; 101 header_.public_header.reset_flag = false;
100 header_.fec_flag = false; 102 header_.fec_flag = false;
101 header_.entropy_flag = false; 103 header_.entropy_flag = false;
102 header_.packet_sequence_number = number; 104 header_.packet_sequence_number = number;
103 header_.is_in_fec_group = fec_group == 0 ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; 105 header_.is_in_fec_group = fec_group == 0 ? NOT_IN_FEC_GROUP : IN_FEC_GROUP;
(...skipping 25 matching lines...) Expand all
129 const int64 kDefaultRetransmissionTimeMs = 500; 131 const int64 kDefaultRetransmissionTimeMs = 500;
130 132
131 const char buffer[] = "foo"; 133 const char buffer[] = "foo";
132 const size_t packet_size = 134 const size_t packet_size =
133 QuicPacketCreator::StreamFramePacketOverhead( 135 QuicPacketCreator::StreamFramePacketOverhead(
134 framer_.version(), PACKET_8BYTE_GUID, kIncludeVersion, 136 framer_.version(), PACKET_8BYTE_GUID, kIncludeVersion,
135 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP) + 137 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP) +
136 arraysize(buffer) - 1; 138 arraysize(buffer) - 1;
137 139
138 EXPECT_CALL(*send_algorithm_, 140 EXPECT_CALL(*send_algorithm_,
139 SentPacket(_, 1, packet_size, NOT_RETRANSMISSION)); 141 SentPacket(_, 1, packet_size, NOT_RETRANSMISSION, _));
140 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, packet_size)); 142 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, packet_size));
141 connection_.SendStreamData(1, buffer, 0, false); 143 struct iovec iov = {const_cast<char*>(buffer),
144 static_cast<size_t>(3)};
145 connection_.SendvStreamData(1, &iov, 1, 0, false);
142 EXPECT_EQ(1u, helper_->header()->packet_sequence_number); 146 EXPECT_EQ(1u, helper_->header()->packet_sequence_number);
143 EXPECT_CALL(*send_algorithm_, 147 EXPECT_CALL(*send_algorithm_,
144 SentPacket(_, 2, packet_size, IS_RETRANSMISSION)); 148 SentPacket(_, 2, packet_size, IS_RETRANSMISSION, _));
145 epoll_server_.AdvanceByAndCallCallbacks(kDefaultRetransmissionTimeMs * 1000); 149 epoll_server_.AdvanceByAndCallCallbacks(kDefaultRetransmissionTimeMs * 1000);
146 150
147 EXPECT_EQ(2u, helper_->header()->packet_sequence_number); 151 EXPECT_EQ(2u, helper_->header()->packet_sequence_number);
148 } 152 }
149 153
150 TEST_F(QuicEpollConnectionHelperTest, InitialTimeout) { 154 TEST_F(QuicEpollConnectionHelperTest, InitialTimeout) {
151 EXPECT_TRUE(connection_.connected()); 155 EXPECT_TRUE(connection_.connected());
152 156
153 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 157 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, _));
154 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer)); 158 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer));
155 epoll_server_.WaitForEventsAndExecuteCallbacks(); 159 epoll_server_.WaitForEventsAndExecuteCallbacks();
156 EXPECT_FALSE(connection_.connected()); 160 EXPECT_FALSE(connection_.connected());
157 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000, epoll_server_.NowInUsec()); 161 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000, epoll_server_.NowInUsec());
158 } 162 }
159 163
160 TEST_F(QuicEpollConnectionHelperTest, TimeoutAfterSend) { 164 TEST_F(QuicEpollConnectionHelperTest, TimeoutAfterSend) {
161 EXPECT_TRUE(connection_.connected()); 165 EXPECT_TRUE(connection_.connected());
162 EXPECT_EQ(0, epoll_server_.NowInUsec()); 166 EXPECT_EQ(0, epoll_server_.NowInUsec());
163 167
164 // When we send a packet, the timeout will change to 5000 + 168 // When we send a packet, the timeout will change to 5000 +
165 // kDefaultInitialTimeoutSecs. 169 // kDefaultInitialTimeoutSecs.
166 epoll_server_.AdvanceBy(5000); 170 epoll_server_.AdvanceBy(5000);
167 EXPECT_EQ(5000, epoll_server_.NowInUsec()); 171 EXPECT_EQ(5000, epoll_server_.NowInUsec());
168 172
169 // Send an ack so we don't set the retransmission alarm. 173 // Send an ack so we don't set the retransmission alarm.
170 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 174 EXPECT_CALL(*send_algorithm_,
175 SentPacket(_, 1, _, NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA));
171 connection_.SendAck(); 176 connection_.SendAck();
172 177
173 // The original alarm will fire. We should not time out because we had a 178 // The original alarm will fire. We should not time out because we had a
174 // network event at t=5000. The alarm will reregister. 179 // network event at t=5000. The alarm will reregister.
175 epoll_server_.WaitForEventsAndExecuteCallbacks(); 180 epoll_server_.WaitForEventsAndExecuteCallbacks();
176 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000, epoll_server_.NowInUsec()); 181 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000, epoll_server_.NowInUsec());
177 182
178 // This time, we should time out. 183 // This time, we should time out.
179 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer)); 184 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer));
180 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, NOT_RETRANSMISSION)); 185 EXPECT_CALL(*send_algorithm_,
186 SentPacket(_, 2, _, NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA));
181 epoll_server_.WaitForEventsAndExecuteCallbacks(); 187 epoll_server_.WaitForEventsAndExecuteCallbacks();
182 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000 + 5000, 188 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000 + 5000,
183 epoll_server_.NowInUsec()); 189 epoll_server_.NowInUsec());
184 EXPECT_FALSE(connection_.connected()); 190 EXPECT_FALSE(connection_.connected());
185 } 191 }
186 192
187 TEST_F(QuicEpollConnectionHelperTest, SendSchedulerDelayThenSend) { 193 TEST_F(QuicEpollConnectionHelperTest, SendSchedulerDelayThenSend) {
188 // Test that if we send a packet with a delay, it ends up queued. 194 // Test that if we send a packet with a delay, it ends up queued.
189 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 195 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
190 Return(QuicTime::Delta::Zero())); 196 Return(QuicTime::Delta::Zero()));
191 QuicPacket* packet = ConstructDataPacket(1, 0); 197 QuicPacket* packet = ConstructDataPacket(1, 0);
192 EXPECT_CALL( 198 EXPECT_CALL(
193 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 199 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
194 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 200 Return(QuicTime::Delta::FromMicroseconds(1)));
195 connection_.SendOrQueuePacket(ENCRYPTION_NONE, 1, packet, 0, 201 connection_.SendOrQueuePacket(ENCRYPTION_NONE, 1, packet, 0,
196 HAS_RETRANSMITTABLE_DATA); 202 HAS_RETRANSMITTABLE_DATA);
197 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 203 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION,
204 _));
198 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 205 EXPECT_EQ(1u, connection_.NumQueuedPackets());
199 206
200 // Advance the clock to fire the alarm, and configure the scheduler 207 // Advance the clock to fire the alarm, and configure the scheduler
201 // to permit the packet to be sent. 208 // to permit the packet to be sent.
202 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)). 209 EXPECT_CALL(*send_algorithm_,
203 WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); 210 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly(
204 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true)); 211 Return(QuicTime::Delta::Zero()));
212 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(Return(true));
205 epoll_server_.AdvanceByAndCallCallbacks(1); 213 epoll_server_.AdvanceByAndCallCallbacks(1);
206 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 214 EXPECT_EQ(0u, connection_.NumQueuedPackets());
207 } 215 }
208 216
209 } // namespace 217 } // namespace
210 } // namespace test 218 } // namespace test
211 } // namespace tools 219 } // namespace tools
212 } // namespace net 220 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.cc ('k') | net/tools/quic/quic_reliable_server_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698