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

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

Issue 15074007: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix for windows Created 7 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 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 11 matching lines...) Expand all
22 using net::tools::test::MockEpollServer; 22 using net::tools::test::MockEpollServer;
23 using testing::_; 23 using testing::_;
24 using testing::Return; 24 using testing::Return;
25 25
26 namespace net { 26 namespace net {
27 namespace tools { 27 namespace tools {
28 namespace test { 28 namespace test {
29 namespace { 29 namespace {
30 30
31 const char data1[] = "foo"; 31 const char data1[] = "foo";
32 const bool kHasData = true; 32 const bool kFromPeer = true;
33 33
34 class TestConnectionHelper : public QuicEpollConnectionHelper { 34 class TestConnectionHelper : public QuicEpollConnectionHelper {
35 public: 35 public:
36 TestConnectionHelper(int fd, EpollServer* eps) 36 TestConnectionHelper(int fd, EpollServer* eps)
37 : QuicEpollConnectionHelper(fd, eps) { 37 : QuicEpollConnectionHelper(fd, eps) {
38 } 38 }
39 39
40 virtual int WritePacketToWire(const QuicEncryptedPacket& packet, 40 virtual int WritePacketToWire(const QuicEncryptedPacket& packet,
41 int* error) OVERRIDE { 41 int* error) OVERRIDE {
42 QuicFramer framer(kQuicVersion1, QuicTime::Zero(), true); 42 QuicFramer framer(kQuicVersion1, QuicTime::Zero(), true);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 SentPacket(_, 2, packet_size, IS_RETRANSMISSION)); 134 SentPacket(_, 2, packet_size, IS_RETRANSMISSION));
135 epoll_server_.AdvanceByAndCallCallbacks(kDefaultRetransmissionTimeMs * 1000); 135 epoll_server_.AdvanceByAndCallCallbacks(kDefaultRetransmissionTimeMs * 1000);
136 136
137 EXPECT_EQ(2u, helper_->header()->packet_sequence_number); 137 EXPECT_EQ(2u, helper_->header()->packet_sequence_number);
138 } 138 }
139 139
140 TEST_F(QuicConnectionHelperTest, InitialTimeout) { 140 TEST_F(QuicConnectionHelperTest, InitialTimeout) {
141 EXPECT_TRUE(connection_.connected()); 141 EXPECT_TRUE(connection_.connected());
142 142
143 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 143 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION));
144 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kHasData)); 144 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer));
145 epoll_server_.WaitForEventsAndExecuteCallbacks(); 145 epoll_server_.WaitForEventsAndExecuteCallbacks();
146 EXPECT_FALSE(connection_.connected()); 146 EXPECT_FALSE(connection_.connected());
147 EXPECT_EQ(kDefaultTimeoutUs, epoll_server_.NowInUsec()); 147 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000, epoll_server_.NowInUsec());
148 } 148 }
149 149
150 TEST_F(QuicConnectionHelperTest, TimeoutAfterSend) { 150 TEST_F(QuicConnectionHelperTest, TimeoutAfterSend) {
151 EXPECT_TRUE(connection_.connected()); 151 EXPECT_TRUE(connection_.connected());
152 EXPECT_EQ(0, epoll_server_.NowInUsec()); 152 EXPECT_EQ(0, epoll_server_.NowInUsec());
153 153
154 // When we send a packet, the timeout will change to 5000 + kDefaultTimeout. 154 // When we send a packet, the timeout will change to 5000 +
155 // kDefaultInitialTimeoutSecs.
155 epoll_server_.AdvanceBy(5000); 156 epoll_server_.AdvanceBy(5000);
156 EXPECT_EQ(5000, epoll_server_.NowInUsec()); 157 EXPECT_EQ(5000, epoll_server_.NowInUsec());
157 158
158 // Send an ack so we don't set the retransmission alarm. 159 // Send an ack so we don't set the retransmission alarm.
159 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 160 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION));
160 connection_.SendAck(); 161 connection_.SendAck();
161 162
162 // The original alarm will fire. We should not time out because we had a 163 // The original alarm will fire. We should not time out because we had a
163 // network event at t=5000. The alarm will reregister. 164 // network event at t=5000. The alarm will reregister.
164 epoll_server_.WaitForEventsAndExecuteCallbacks(); 165 epoll_server_.WaitForEventsAndExecuteCallbacks();
165 EXPECT_EQ(kDefaultTimeoutUs, epoll_server_.NowInUsec()); 166 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000, epoll_server_.NowInUsec());
166 167
167 // This time, we should time out. 168 // This time, we should time out.
168 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); 169 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer));
169 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, NOT_RETRANSMISSION)); 170 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, NOT_RETRANSMISSION));
170 epoll_server_.WaitForEventsAndExecuteCallbacks(); 171 epoll_server_.WaitForEventsAndExecuteCallbacks();
171 EXPECT_EQ(kDefaultTimeoutUs + 5000, epoll_server_.NowInUsec()); 172 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000 + 5000,
173 epoll_server_.NowInUsec());
172 EXPECT_FALSE(connection_.connected()); 174 EXPECT_FALSE(connection_.connected());
173 } 175 }
174 176
175 TEST_F(QuicConnectionHelperTest, SendSchedulerDelayThenSend) { 177 TEST_F(QuicConnectionHelperTest, SendSchedulerDelayThenSend) {
176 // Test that if we send a packet with a delay, it ends up queued. 178 // Test that if we send a packet with a delay, it ends up queued.
177 QuicPacket* packet = ConstructDataPacket(1, 0); 179 QuicPacket* packet = ConstructDataPacket(1, 0);
178 EXPECT_CALL( 180 EXPECT_CALL(
179 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillOnce( 181 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillOnce(
180 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 182 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
181 connection_.SendOrQueuePacket(ENCRYPTION_NONE, 1, packet, 0, 183 connection_.SendOrQueuePacket(ENCRYPTION_NONE, 1, packet, 0,
182 HAS_RETRANSMITTABLE_DATA); 184 HAS_RETRANSMITTABLE_DATA);
183 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 185 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION));
184 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 186 EXPECT_EQ(1u, connection_.NumQueuedPackets());
185 187
186 // Advance the clock to fire the alarm, and configure the scheduler 188 // Advance the clock to fire the alarm, and configure the scheduler
187 // to permit the packet to be sent. 189 // to permit the packet to be sent.
188 EXPECT_CALL( 190 EXPECT_CALL(
189 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillRepeatedly( 191 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillRepeatedly(
190 testing::Return(QuicTime::Delta::Zero())); 192 testing::Return(QuicTime::Delta::Zero()));
191 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true)); 193 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true));
192 epoll_server_.AdvanceByAndCallCallbacks(1); 194 epoll_server_.AdvanceByAndCallCallbacks(1);
193 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 195 EXPECT_EQ(0u, connection_.NumQueuedPackets());
194 } 196 }
195 197
196 } // namespace 198 } // namespace
197 } // namespace test 199 } // namespace test
198 } // namespace tools 200 } // namespace tools
199 } // namespace net 201 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_epoll_connection_helper.h ('k') | net/tools/quic/quic_reliable_client_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698