| 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/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" |
| 11 #include "net/quic/quic_connection.h" |
| 11 #include "net/quic/quic_framer.h" | 12 #include "net/quic/quic_framer.h" |
| 12 #include "net/quic/test_tools/quic_connection_peer.h" | 13 #include "net/quic/test_tools/quic_connection_peer.h" |
| 13 #include "net/quic/test_tools/quic_test_utils.h" | 14 #include "net/quic/test_tools/quic_test_utils.h" |
| 14 #include "net/tools/quic/test_tools/mock_epoll_server.h" | 15 #include "net/tools/quic/test_tools/mock_epoll_server.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 using net::test::FramerVisitorCapturingFrames; | 19 using net::test::FramerVisitorCapturingFrames; |
| 19 using net::test::MockSendAlgorithm; | 20 using net::test::MockSendAlgorithm; |
| 20 using net::test::QuicConnectionPeer; | 21 using net::test::QuicConnectionPeer; |
| 21 using net::test::MockConnectionVisitor; | 22 using net::test::MockConnectionVisitor; |
| 22 using net::tools::test::MockEpollServer; | 23 using net::tools::test::MockEpollServer; |
| 23 using testing::_; | 24 using testing::_; |
| 25 using testing::AnyNumber; |
| 24 using testing::Return; | 26 using testing::Return; |
| 25 | 27 |
| 26 namespace net { | 28 namespace net { |
| 27 namespace tools { | 29 namespace tools { |
| 28 namespace test { | 30 namespace test { |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 const char data1[] = "foo"; | 33 const char data1[] = "foo"; |
| 32 const bool kFromPeer = true; | 34 const bool kFromPeer = true; |
| 33 | 35 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 EXPECT_CALL(*send_algorithm_, | 149 EXPECT_CALL(*send_algorithm_, |
| 148 SentPacket(_, 2, packet_size, IS_RETRANSMISSION, _)); | 150 SentPacket(_, 2, packet_size, IS_RETRANSMISSION, _)); |
| 149 epoll_server_.AdvanceByAndCallCallbacks(kDefaultRetransmissionTimeMs * 1000); | 151 epoll_server_.AdvanceByAndCallCallbacks(kDefaultRetransmissionTimeMs * 1000); |
| 150 | 152 |
| 151 EXPECT_EQ(2u, helper_->header()->packet_sequence_number); | 153 EXPECT_EQ(2u, helper_->header()->packet_sequence_number); |
| 152 } | 154 } |
| 153 | 155 |
| 154 TEST_F(QuicEpollConnectionHelperTest, InitialTimeout) { | 156 TEST_F(QuicEpollConnectionHelperTest, InitialTimeout) { |
| 155 EXPECT_TRUE(connection_.connected()); | 157 EXPECT_TRUE(connection_.connected()); |
| 156 | 158 |
| 157 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, _)); | 159 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, |
| 160 HAS_RETRANSMITTABLE_DATA)); |
| 161 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillOnce( |
| 162 Return(QuicTime::Delta::FromMicroseconds(1))); |
| 158 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer)); | 163 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer)); |
| 159 epoll_server_.WaitForEventsAndExecuteCallbacks(); | 164 epoll_server_.WaitForEventsAndExecuteCallbacks(); |
| 160 EXPECT_FALSE(connection_.connected()); | 165 EXPECT_FALSE(connection_.connected()); |
| 161 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000, epoll_server_.NowInUsec()); | 166 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000, epoll_server_.NowInUsec()); |
| 162 } | 167 } |
| 163 | 168 |
| 164 TEST_F(QuicEpollConnectionHelperTest, TimeoutAfterSend) { | 169 TEST_F(QuicEpollConnectionHelperTest, TimeoutAfterSend) { |
| 165 EXPECT_TRUE(connection_.connected()); | 170 EXPECT_TRUE(connection_.connected()); |
| 166 EXPECT_EQ(0, epoll_server_.NowInUsec()); | 171 EXPECT_EQ(0, epoll_server_.NowInUsec()); |
| 167 | 172 |
| 168 // When we send a packet, the timeout will change to 5000 + | 173 // When we send a packet, the timeout will change to 5000 + |
| 169 // kDefaultInitialTimeoutSecs. | 174 // kDefaultInitialTimeoutSecs. |
| 170 epoll_server_.AdvanceBy(5000); | 175 epoll_server_.AdvanceBy(5000); |
| 171 EXPECT_EQ(5000, epoll_server_.NowInUsec()); | 176 EXPECT_EQ(5000, epoll_server_.NowInUsec()); |
| 172 | 177 |
| 173 // Send an ack so we don't set the retransmission alarm. | 178 // Send an ack so we don't set the retransmission alarm. |
| 174 EXPECT_CALL(*send_algorithm_, | 179 EXPECT_CALL(*send_algorithm_, |
| 175 SentPacket(_, 1, _, NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA)); | 180 SentPacket(_, 1, _, NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA)); |
| 176 connection_.SendAck(); | 181 connection_.SendAck(); |
| 177 | 182 |
| 178 // The original alarm will fire. We should not time out because we had a | 183 // The original alarm will fire. We should not time out because we had a |
| 179 // network event at t=5000. The alarm will reregister. | 184 // network event at t=5000. The alarm will reregister. |
| 180 epoll_server_.WaitForEventsAndExecuteCallbacks(); | 185 epoll_server_.WaitForEventsAndExecuteCallbacks(); |
| 181 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000, epoll_server_.NowInUsec()); | 186 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000, epoll_server_.NowInUsec()); |
| 182 | 187 |
| 183 // This time, we should time out. | 188 // This time, we should time out. |
| 184 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer)); | 189 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer)); |
| 185 EXPECT_CALL(*send_algorithm_, | 190 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, NOT_RETRANSMISSION, |
| 186 SentPacket(_, 2, _, NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA)); | 191 HAS_RETRANSMITTABLE_DATA)); |
| 192 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillOnce( |
| 193 Return(QuicTime::Delta::FromMicroseconds(1))); |
| 187 epoll_server_.WaitForEventsAndExecuteCallbacks(); | 194 epoll_server_.WaitForEventsAndExecuteCallbacks(); |
| 188 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000 + 5000, | 195 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000 + 5000, |
| 189 epoll_server_.NowInUsec()); | 196 epoll_server_.NowInUsec()); |
| 190 EXPECT_FALSE(connection_.connected()); | 197 EXPECT_FALSE(connection_.connected()); |
| 191 } | 198 } |
| 192 | 199 |
| 193 TEST_F(QuicEpollConnectionHelperTest, SendSchedulerDelayThenSend) { | 200 TEST_F(QuicEpollConnectionHelperTest, SendSchedulerDelayThenSend) { |
| 194 // Test that if we send a packet with a delay, it ends up queued. | 201 // Test that if we send a packet with a delay, it ends up queued. |
| 195 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( | 202 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( |
| 196 Return(QuicTime::Delta::Zero())); | 203 Return(QuicTime::Delta::Zero())); |
| 197 QuicPacket* packet = ConstructDataPacket(1, 0); | 204 QuicPacket* packet = ConstructDataPacket(1, 0); |
| 198 EXPECT_CALL( | 205 EXPECT_CALL( |
| 199 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 206 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
| 200 Return(QuicTime::Delta::FromMicroseconds(1))); | 207 Return(QuicTime::Delta::FromMicroseconds(1))); |
| 201 connection_.SendOrQueuePacket(ENCRYPTION_NONE, 1, packet, 0, | 208 connection_.SendOrQueuePacket(ENCRYPTION_NONE, 1, packet, 0, |
| 202 HAS_RETRANSMITTABLE_DATA); | 209 HAS_RETRANSMITTABLE_DATA, |
| 210 QuicConnection::NO_FORCE); |
| 203 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, | 211 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, |
| 204 _)); | 212 _)); |
| 205 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 213 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 206 | 214 |
| 207 // Advance the clock to fire the alarm, and configure the scheduler | 215 // Advance the clock to fire the alarm, and configure the scheduler |
| 208 // to permit the packet to be sent. | 216 // to permit the packet to be sent. |
| 209 EXPECT_CALL(*send_algorithm_, | 217 EXPECT_CALL(*send_algorithm_, |
| 210 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( | 218 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( |
| 211 Return(QuicTime::Delta::Zero())); | 219 Return(QuicTime::Delta::Zero())); |
| 212 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(Return(true)); | 220 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(Return(true)); |
| 221 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); |
| 213 epoll_server_.AdvanceByAndCallCallbacks(1); | 222 epoll_server_.AdvanceByAndCallCallbacks(1); |
| 214 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 223 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 215 } | 224 } |
| 216 | 225 |
| 217 } // namespace | 226 } // namespace |
| 218 } // namespace test | 227 } // namespace test |
| 219 } // namespace tools | 228 } // namespace tools |
| 220 } // namespace net | 229 } // namespace net |
| OLD | NEW |