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

Side by Side Diff: net/quic/test_tools/simulator/quic_endpoint_test.cc

Issue 2808273006: Landing Recent QUIC changes until Sun Apr 9 16:12:55 (Closed)
Patch Set: increment enabled_options in e2e test Created 3 years, 8 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 | « net/quic/test_tools/quic_test_utils.cc ('k') | net/tools/quic/chlo_extractor_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/quic/test_tools/simulator/quic_endpoint.h" 5 #include "net/quic/test_tools/simulator/quic_endpoint.h"
6 6
7 #include "net/quic/platform/api/quic_ptr_util.h" 7 #include "net/quic/platform/api/quic_ptr_util.h"
8 #include "net/quic/test_tools/quic_connection_peer.h" 8 #include "net/quic/test_tools/quic_connection_peer.h"
9 #include "net/quic/test_tools/quic_test_utils.h" 9 #include "net/quic/test_tools/quic_test_utils.h"
10 #include "net/quic/test_tools/simulator/simulator.h" 10 #include "net/quic/test_tools/simulator/simulator.h"
11 #include "net/quic/test_tools/simulator/switch.h" 11 #include "net/quic/test_tools/simulator/switch.h"
12 12
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using ::testing::_; 16 using ::testing::_;
17 using ::testing::NiceMock; 17 using ::testing::NiceMock;
18 using ::testing::Return; 18 using ::testing::Return;
19 using net::test::GetPeerInMemoryConnectionId;
19 20
20 namespace net { 21 namespace net {
21 namespace simulator { 22 namespace simulator {
22 23
23 const QuicBandwidth kDefaultBandwidth = 24 const QuicBandwidth kDefaultBandwidth =
24 QuicBandwidth::FromKBitsPerSecond(10 * 1000); 25 QuicBandwidth::FromKBitsPerSecond(10 * 1000);
25 const QuicTime::Delta kDefaultPropagationDelay = 26 const QuicTime::Delta kDefaultPropagationDelay =
26 QuicTime::Delta::FromMilliseconds(20); 27 QuicTime::Delta::FromMilliseconds(20);
27 const QuicByteCount kDefaultBdp = kDefaultBandwidth * kDefaultPropagationDelay; 28 const QuicByteCount kDefaultBdp = kDefaultBandwidth * kDefaultPropagationDelay;
28 29
(...skipping 12 matching lines...) Expand all
41 return QuicMakeUnique<SymmetricLink>(a, b, kDefaultBandwidth, 42 return QuicMakeUnique<SymmetricLink>(a, b, kDefaultBandwidth,
42 kDefaultPropagationDelay); 43 kDefaultPropagationDelay);
43 } 44 }
44 }; 45 };
45 46
46 // Test transmission from one host to another. 47 // Test transmission from one host to another.
47 TEST_F(QuicEndpointTest, OneWayTransmission) { 48 TEST_F(QuicEndpointTest, OneWayTransmission) {
48 QuicEndpoint endpoint_a(&simulator_, "Endpoint A", "Endpoint B", 49 QuicEndpoint endpoint_a(&simulator_, "Endpoint A", "Endpoint B",
49 Perspective::IS_CLIENT, 42); 50 Perspective::IS_CLIENT, 42);
50 QuicEndpoint endpoint_b(&simulator_, "Endpoint B", "Endpoint A", 51 QuicEndpoint endpoint_b(&simulator_, "Endpoint B", "Endpoint A",
51 Perspective::IS_SERVER, 42); 52 Perspective::IS_SERVER,
53 GetPeerInMemoryConnectionId(42));
52 auto link_a = Link(&endpoint_a, switch_.port(1)); 54 auto link_a = Link(&endpoint_a, switch_.port(1));
53 auto link_b = Link(&endpoint_b, switch_.port(2)); 55 auto link_b = Link(&endpoint_b, switch_.port(2));
54 56
55 // First transmit a small, packet-size chunk of data. 57 // First transmit a small, packet-size chunk of data.
56 endpoint_a.AddBytesToTransfer(600); 58 endpoint_a.AddBytesToTransfer(600);
57 QuicTime end_time = 59 QuicTime end_time =
58 simulator_.GetClock()->Now() + QuicTime::Delta::FromMilliseconds(1000); 60 simulator_.GetClock()->Now() + QuicTime::Delta::FromMilliseconds(1000);
59 simulator_.RunUntil( 61 simulator_.RunUntil(
60 [this, end_time]() { return simulator_.GetClock()->Now() >= end_time; }); 62 [this, end_time]() { return simulator_.GetClock()->Now() >= end_time; });
61 63
(...skipping 14 matching lines...) Expand all
76 EXPECT_EQ(0u, endpoint_a.write_blocked_count()); 78 EXPECT_EQ(0u, endpoint_a.write_blocked_count());
77 EXPECT_FALSE(endpoint_a.wrong_data_received()); 79 EXPECT_FALSE(endpoint_a.wrong_data_received());
78 EXPECT_FALSE(endpoint_b.wrong_data_received()); 80 EXPECT_FALSE(endpoint_b.wrong_data_received());
79 } 81 }
80 82
81 // Test the situation in which the writer becomes write-blocked. 83 // Test the situation in which the writer becomes write-blocked.
82 TEST_F(QuicEndpointTest, WriteBlocked) { 84 TEST_F(QuicEndpointTest, WriteBlocked) {
83 QuicEndpoint endpoint_a(&simulator_, "Endpoint A", "Endpoint B", 85 QuicEndpoint endpoint_a(&simulator_, "Endpoint A", "Endpoint B",
84 Perspective::IS_CLIENT, 42); 86 Perspective::IS_CLIENT, 42);
85 QuicEndpoint endpoint_b(&simulator_, "Endpoint B", "Endpoint A", 87 QuicEndpoint endpoint_b(&simulator_, "Endpoint B", "Endpoint A",
86 Perspective::IS_SERVER, 42); 88 Perspective::IS_SERVER,
89 GetPeerInMemoryConnectionId(42));
87 auto link_a = Link(&endpoint_a, switch_.port(1)); 90 auto link_a = Link(&endpoint_a, switch_.port(1));
88 auto link_b = Link(&endpoint_b, switch_.port(2)); 91 auto link_b = Link(&endpoint_b, switch_.port(2));
89 92
90 // Will be owned by the sent packet manager. 93 // Will be owned by the sent packet manager.
91 auto* sender = new NiceMock<test::MockSendAlgorithm>(); 94 auto* sender = new NiceMock<test::MockSendAlgorithm>();
92 EXPECT_CALL(*sender, TimeUntilSend(_, _)) 95 EXPECT_CALL(*sender, TimeUntilSend(_, _))
93 .WillRepeatedly(Return(QuicTime::Delta::Zero())); 96 .WillRepeatedly(Return(QuicTime::Delta::Zero()));
94 EXPECT_CALL(*sender, PacingRate(_)) 97 EXPECT_CALL(*sender, PacingRate(_))
95 .WillRepeatedly(Return(10 * kDefaultBandwidth)); 98 .WillRepeatedly(Return(10 * kDefaultBandwidth));
96 EXPECT_CALL(*sender, BandwidthEstimate()) 99 EXPECT_CALL(*sender, BandwidthEstimate())
(...skipping 19 matching lines...) Expand all
116 EXPECT_FALSE(endpoint_a.wrong_data_received()); 119 EXPECT_FALSE(endpoint_a.wrong_data_received());
117 EXPECT_FALSE(endpoint_b.wrong_data_received()); 120 EXPECT_FALSE(endpoint_b.wrong_data_received());
118 } 121 }
119 122
120 // Test transmission of 1 MiB of data between two hosts simultaneously in both 123 // Test transmission of 1 MiB of data between two hosts simultaneously in both
121 // directions. 124 // directions.
122 TEST_F(QuicEndpointTest, TwoWayTransmission) { 125 TEST_F(QuicEndpointTest, TwoWayTransmission) {
123 QuicEndpoint endpoint_a(&simulator_, "Endpoint A", "Endpoint B", 126 QuicEndpoint endpoint_a(&simulator_, "Endpoint A", "Endpoint B",
124 Perspective::IS_CLIENT, 42); 127 Perspective::IS_CLIENT, 42);
125 QuicEndpoint endpoint_b(&simulator_, "Endpoint B", "Endpoint A", 128 QuicEndpoint endpoint_b(&simulator_, "Endpoint B", "Endpoint A",
126 Perspective::IS_SERVER, 42); 129 Perspective::IS_SERVER,
130 GetPeerInMemoryConnectionId(42));
127 auto link_a = Link(&endpoint_a, switch_.port(1)); 131 auto link_a = Link(&endpoint_a, switch_.port(1));
128 auto link_b = Link(&endpoint_b, switch_.port(2)); 132 auto link_b = Link(&endpoint_b, switch_.port(2));
129 133
130 endpoint_a.AddBytesToTransfer(1024 * 1024); 134 endpoint_a.AddBytesToTransfer(1024 * 1024);
131 endpoint_b.AddBytesToTransfer(1024 * 1024); 135 endpoint_b.AddBytesToTransfer(1024 * 1024);
132 QuicTime end_time = 136 QuicTime end_time =
133 simulator_.GetClock()->Now() + QuicTime::Delta::FromSeconds(5); 137 simulator_.GetClock()->Now() + QuicTime::Delta::FromSeconds(5);
134 simulator_.RunUntil( 138 simulator_.RunUntil(
135 [this, end_time]() { return simulator_.GetClock()->Now() >= end_time; }); 139 [this, end_time]() { return simulator_.GetClock()->Now() >= end_time; });
136 140
137 EXPECT_EQ(1024u * 1024u, endpoint_a.bytes_transferred()); 141 EXPECT_EQ(1024u * 1024u, endpoint_a.bytes_transferred());
138 EXPECT_EQ(1024u * 1024u, endpoint_b.bytes_transferred()); 142 EXPECT_EQ(1024u * 1024u, endpoint_b.bytes_transferred());
139 EXPECT_EQ(1024u * 1024u, endpoint_a.bytes_received()); 143 EXPECT_EQ(1024u * 1024u, endpoint_a.bytes_received());
140 EXPECT_EQ(1024u * 1024u, endpoint_b.bytes_received()); 144 EXPECT_EQ(1024u * 1024u, endpoint_b.bytes_received());
141 EXPECT_FALSE(endpoint_a.wrong_data_received()); 145 EXPECT_FALSE(endpoint_a.wrong_data_received());
142 EXPECT_FALSE(endpoint_b.wrong_data_received()); 146 EXPECT_FALSE(endpoint_b.wrong_data_received());
143 } 147 }
144 148
145 // Simulate three hosts trying to send data to a fourth one simultaneously. 149 // Simulate three hosts trying to send data to a fourth one simultaneously.
146 TEST_F(QuicEndpointTest, Competition) { 150 TEST_F(QuicEndpointTest, Competition) {
147 simulator_.set_enable_random_delays(true); 151 simulator_.set_enable_random_delays(true);
148 152
149 auto endpoint_a = QuicMakeUnique<QuicEndpoint>( 153 auto endpoint_a = QuicMakeUnique<QuicEndpoint>(
150 &simulator_, "Endpoint A", "Endpoint D (A)", Perspective::IS_CLIENT, 42); 154 &simulator_, "Endpoint A", "Endpoint D (A)", Perspective::IS_CLIENT, 42);
151 auto endpoint_b = QuicMakeUnique<QuicEndpoint>( 155 auto endpoint_b = QuicMakeUnique<QuicEndpoint>(
152 &simulator_, "Endpoint B", "Endpoint D (B)", Perspective::IS_CLIENT, 43); 156 &simulator_, "Endpoint B", "Endpoint D (B)", Perspective::IS_CLIENT, 43);
153 auto endpoint_c = QuicMakeUnique<QuicEndpoint>( 157 auto endpoint_c = QuicMakeUnique<QuicEndpoint>(
154 &simulator_, "Endpoint C", "Endpoint D (C)", Perspective::IS_CLIENT, 44); 158 &simulator_, "Endpoint C", "Endpoint D (C)", Perspective::IS_CLIENT, 44);
155 auto endpoint_d_a = QuicMakeUnique<QuicEndpoint>( 159 auto endpoint_d_a = QuicMakeUnique<QuicEndpoint>(
156 &simulator_, "Endpoint D (A)", "Endpoint A", Perspective::IS_SERVER, 42); 160 &simulator_, "Endpoint D (A)", "Endpoint A", Perspective::IS_SERVER,
161 GetPeerInMemoryConnectionId(42));
157 auto endpoint_d_b = QuicMakeUnique<QuicEndpoint>( 162 auto endpoint_d_b = QuicMakeUnique<QuicEndpoint>(
158 &simulator_, "Endpoint D (B)", "Endpoint B", Perspective::IS_SERVER, 43); 163 &simulator_, "Endpoint D (B)", "Endpoint B", Perspective::IS_SERVER,
164 GetPeerInMemoryConnectionId(43));
159 auto endpoint_d_c = QuicMakeUnique<QuicEndpoint>( 165 auto endpoint_d_c = QuicMakeUnique<QuicEndpoint>(
160 &simulator_, "Endpoint D (C)", "Endpoint C", Perspective::IS_SERVER, 44); 166 &simulator_, "Endpoint D (C)", "Endpoint C", Perspective::IS_SERVER,
167 GetPeerInMemoryConnectionId(44));
161 QuicEndpointMultiplexer endpoint_d( 168 QuicEndpointMultiplexer endpoint_d(
162 "Endpoint D", 169 "Endpoint D",
163 {endpoint_d_a.get(), endpoint_d_b.get(), endpoint_d_c.get()}); 170 {endpoint_d_a.get(), endpoint_d_b.get(), endpoint_d_c.get()});
164 171
165 auto link_a = Link(endpoint_a.get(), switch_.port(1)); 172 auto link_a = Link(endpoint_a.get(), switch_.port(1));
166 auto link_b = Link(endpoint_b.get(), switch_.port(2)); 173 auto link_b = Link(endpoint_b.get(), switch_.port(2));
167 auto link_c = Link(endpoint_c.get(), switch_.port(3)); 174 auto link_c = Link(endpoint_c.get(), switch_.port(3));
168 auto link_d = Link(&endpoint_d, switch_.port(4)); 175 auto link_d = Link(&endpoint_d, switch_.port(4));
169 176
170 endpoint_a->AddBytesToTransfer(2 * 1024 * 1024); 177 endpoint_a->AddBytesToTransfer(2 * 1024 * 1024);
(...skipping 11 matching lines...) Expand all
182 } 189 }
183 for (QuicEndpoint* endpoint : 190 for (QuicEndpoint* endpoint :
184 {endpoint_d_a.get(), endpoint_d_b.get(), endpoint_d_c.get()}) { 191 {endpoint_d_a.get(), endpoint_d_b.get(), endpoint_d_c.get()}) {
185 EXPECT_EQ(2u * 1024u * 1024u, endpoint->bytes_received()); 192 EXPECT_EQ(2u * 1024u * 1024u, endpoint->bytes_received());
186 EXPECT_FALSE(endpoint->wrong_data_received()); 193 EXPECT_FALSE(endpoint->wrong_data_received());
187 } 194 }
188 } 195 }
189 196
190 } // namespace simulator 197 } // namespace simulator
191 } // namespace net 198 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.cc ('k') | net/tools/quic/chlo_extractor_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698