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

Side by Side Diff: webrtc/p2p/base/stunport_unittest.cc

Issue 2680233002: Use fake clock in some more networks tests. (Closed)
Patch Set: Use a different fake clock thing. Created 3 years, 10 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 | « webrtc/base/signalthread.cc ('k') | webrtc/p2p/client/basicportallocator_unittest.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 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 25 matching lines...) Expand all
36 // fix flaky tests. 36 // fix flaky tests.
37 static const int kTimeoutMs = 15000; 37 static const int kTimeoutMs = 15000;
38 // stun prio = 100 << 24 | 30 (IPV4) << 8 | 256 - 0 38 // stun prio = 100 << 24 | 30 (IPV4) << 8 | 256 - 0
39 static const uint32_t kStunCandidatePriority = 1677729535; 39 static const uint32_t kStunCandidatePriority = 1677729535;
40 static const int kInfiniteLifetime = -1; 40 static const int kInfiniteLifetime = -1;
41 static const int kHighCostPortKeepaliveLifetimeMs = 2 * 60 * 1000; 41 static const int kHighCostPortKeepaliveLifetimeMs = 2 * 60 * 1000;
42 42
43 // Tests connecting a StunPort to a fake STUN server (cricket::StunServer) 43 // Tests connecting a StunPort to a fake STUN server (cricket::StunServer)
44 // TODO: Use a VirtualSocketServer here. We have to use a 44 // TODO: Use a VirtualSocketServer here. We have to use a
45 // PhysicalSocketServer right now since DNS is not part of SocketServer yet. 45 // PhysicalSocketServer right now since DNS is not part of SocketServer yet.
46 class StunPortTest : public testing::Test, 46 class StunPortTestBase : public testing::Test, public sigslot::has_slots<> {
47 public sigslot::has_slots<> {
48 public: 47 public:
49 StunPortTest() 48 StunPortTestBase()
50 : pss_(new rtc::PhysicalSocketServer), 49 : pss_(new rtc::PhysicalSocketServer),
51 ss_(new rtc::VirtualSocketServer(pss_.get())), 50 ss_(new rtc::VirtualSocketServer(pss_.get())),
52 ss_scope_(ss_.get()), 51 ss_scope_(ss_.get()),
53 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), 52 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32),
54 socket_factory_(rtc::Thread::Current()), 53 socket_factory_(rtc::Thread::Current()),
55 stun_server_1_(cricket::TestStunServer::Create(rtc::Thread::Current(), 54 stun_server_1_(cricket::TestStunServer::Create(rtc::Thread::Current(),
56 kStunAddr1)), 55 kStunAddr1)),
57 stun_server_2_(cricket::TestStunServer::Create(rtc::Thread::Current(), 56 stun_server_2_(cricket::TestStunServer::Create(rtc::Thread::Current(),
58 kStunAddr2)), 57 kStunAddr2)),
59 done_(false), 58 done_(false),
60 error_(false), 59 error_(false),
61 stun_keepalive_delay_(0), 60 stun_keepalive_delay_(1),
62 stun_keepalive_lifetime_(-1) {} 61 stun_keepalive_lifetime_(-1) {}
63 62
64 cricket::UDPPort* port() const { return stun_port_.get(); } 63 cricket::UDPPort* port() const { return stun_port_.get(); }
65 bool done() const { return done_; } 64 bool done() const { return done_; }
66 bool error() const { return error_; } 65 bool error() const { return error_; }
67 66
68 void SetNetworkType(rtc::AdapterType adapter_type) { 67 void SetNetworkType(rtc::AdapterType adapter_type) {
69 network_.set_type(adapter_type); 68 network_.set_type(adapter_type);
70 } 69 }
71 70
72 void CreateStunPort(const rtc::SocketAddress& server_addr) { 71 void CreateStunPort(const rtc::SocketAddress& server_addr) {
73 ServerAddresses stun_servers; 72 ServerAddresses stun_servers;
74 stun_servers.insert(server_addr); 73 stun_servers.insert(server_addr);
75 CreateStunPort(stun_servers); 74 CreateStunPort(stun_servers);
76 } 75 }
77 76
78 void CreateStunPort(const ServerAddresses& stun_servers) { 77 void CreateStunPort(const ServerAddresses& stun_servers) {
79 stun_port_.reset(cricket::StunPort::Create( 78 stun_port_.reset(cricket::StunPort::Create(
80 rtc::Thread::Current(), &socket_factory_, &network_, 79 rtc::Thread::Current(), &socket_factory_, &network_,
81 kLocalAddr.ipaddr(), 0, 0, rtc::CreateRandomString(16), 80 kLocalAddr.ipaddr(), 0, 0, rtc::CreateRandomString(16),
82 rtc::CreateRandomString(22), stun_servers, std::string())); 81 rtc::CreateRandomString(22), stun_servers, std::string()));
83 stun_port_->set_stun_keepalive_delay(stun_keepalive_delay_); 82 stun_port_->set_stun_keepalive_delay(stun_keepalive_delay_);
84 // If |stun_keepalive_lifetime_| is negative, let the stun port 83 // If |stun_keepalive_lifetime_| is negative, let the stun port
85 // choose its lifetime from the network type. 84 // choose its lifetime from the network type.
86 if (stun_keepalive_lifetime_ >= 0) { 85 if (stun_keepalive_lifetime_ >= 0) {
87 stun_port_->set_stun_keepalive_lifetime(stun_keepalive_lifetime_); 86 stun_port_->set_stun_keepalive_lifetime(stun_keepalive_lifetime_);
88 } 87 }
89 stun_port_->SignalPortComplete.connect(this, 88 stun_port_->SignalPortComplete.connect(this,
90 &StunPortTest::OnPortComplete); 89 &StunPortTestBase::OnPortComplete);
91 stun_port_->SignalPortError.connect(this, 90 stun_port_->SignalPortError.connect(this, &StunPortTestBase::OnPortError);
92 &StunPortTest::OnPortError);
93 } 91 }
94 92
95 void CreateSharedUdpPort(const rtc::SocketAddress& server_addr) { 93 void CreateSharedUdpPort(const rtc::SocketAddress& server_addr) {
96 socket_.reset(socket_factory_.CreateUdpSocket( 94 socket_.reset(socket_factory_.CreateUdpSocket(
97 rtc::SocketAddress(kLocalAddr.ipaddr(), 0), 0, 0)); 95 rtc::SocketAddress(kLocalAddr.ipaddr(), 0), 0, 0));
98 ASSERT_TRUE(socket_ != NULL); 96 ASSERT_TRUE(socket_ != NULL);
99 socket_->SignalReadPacket.connect(this, &StunPortTest::OnReadPacket); 97 socket_->SignalReadPacket.connect(this, &StunPortTestBase::OnReadPacket);
100 stun_port_.reset(cricket::UDPPort::Create( 98 stun_port_.reset(cricket::UDPPort::Create(
101 rtc::Thread::Current(), &socket_factory_, 99 rtc::Thread::Current(), &socket_factory_,
102 &network_, socket_.get(), 100 &network_, socket_.get(),
103 rtc::CreateRandomString(16), rtc::CreateRandomString(22), 101 rtc::CreateRandomString(16), rtc::CreateRandomString(22),
104 std::string(), false)); 102 std::string(), false));
105 ASSERT_TRUE(stun_port_ != NULL); 103 ASSERT_TRUE(stun_port_ != NULL);
106 ServerAddresses stun_servers; 104 ServerAddresses stun_servers;
107 stun_servers.insert(server_addr); 105 stun_servers.insert(server_addr);
108 stun_port_->set_server_addresses(stun_servers); 106 stun_port_->set_server_addresses(stun_servers);
109 stun_port_->SignalPortComplete.connect(this, 107 stun_port_->SignalPortComplete.connect(this,
110 &StunPortTest::OnPortComplete); 108 &StunPortTestBase::OnPortComplete);
111 stun_port_->SignalPortError.connect(this, 109 stun_port_->SignalPortError.connect(this, &StunPortTestBase::OnPortError);
112 &StunPortTest::OnPortError);
113 } 110 }
114 111
115 void PrepareAddress() { 112 void PrepareAddress() {
116 stun_port_->PrepareAddress(); 113 stun_port_->PrepareAddress();
117 } 114 }
118 115
119 void OnReadPacket(rtc::AsyncPacketSocket* socket, const char* data, 116 void OnReadPacket(rtc::AsyncPacketSocket* socket, const char* data,
120 size_t size, const rtc::SocketAddress& remote_addr, 117 size_t size, const rtc::SocketAddress& remote_addr,
121 const rtc::PacketTime& packet_time) { 118 const rtc::PacketTime& packet_time) {
122 stun_port_->HandleIncomingPacket( 119 stun_port_->HandleIncomingPacket(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 std::unique_ptr<cricket::UDPPort> stun_port_; 166 std::unique_ptr<cricket::UDPPort> stun_port_;
170 std::unique_ptr<cricket::TestStunServer> stun_server_1_; 167 std::unique_ptr<cricket::TestStunServer> stun_server_1_;
171 std::unique_ptr<cricket::TestStunServer> stun_server_2_; 168 std::unique_ptr<cricket::TestStunServer> stun_server_2_;
172 std::unique_ptr<rtc::AsyncPacketSocket> socket_; 169 std::unique_ptr<rtc::AsyncPacketSocket> socket_;
173 bool done_; 170 bool done_;
174 bool error_; 171 bool error_;
175 int stun_keepalive_delay_; 172 int stun_keepalive_delay_;
176 int stun_keepalive_lifetime_; 173 int stun_keepalive_lifetime_;
177 }; 174 };
178 175
176 class StunPortTestWithRealClock : public StunPortTestBase {};
177
178 class FakeClockBase {
179 public:
180 rtc::ScopedFakeClock fake_clock;
181 };
182
183 class StunPortTest : public FakeClockBase, public StunPortTestBase {};
184
179 // Test that we can create a STUN port. 185 // Test that we can create a STUN port.
180 TEST_F(StunPortTest, TestCreateStunPort) { 186 TEST_F(StunPortTest, TestCreateStunPort) {
181 CreateStunPort(kStunAddr1); 187 CreateStunPort(kStunAddr1);
182 EXPECT_EQ("stun", port()->Type()); 188 EXPECT_EQ("stun", port()->Type());
183 EXPECT_EQ(0U, port()->Candidates().size()); 189 EXPECT_EQ(0U, port()->Candidates().size());
184 } 190 }
185 191
186 // Test that we can create a UDP port. 192 // Test that we can create a UDP port.
187 TEST_F(StunPortTest, TestCreateUdpPort) { 193 TEST_F(StunPortTest, TestCreateUdpPort) {
188 CreateSharedUdpPort(kStunAddr1); 194 CreateSharedUdpPort(kStunAddr1);
189 EXPECT_EQ("local", port()->Type()); 195 EXPECT_EQ("local", port()->Type());
190 EXPECT_EQ(0U, port()->Candidates().size()); 196 EXPECT_EQ(0U, port()->Candidates().size());
191 } 197 }
192 198
193 // Test that we can get an address from a STUN server. 199 // Test that we can get an address from a STUN server.
194 TEST_F(StunPortTest, TestPrepareAddress) { 200 TEST_F(StunPortTest, TestPrepareAddress) {
195 CreateStunPort(kStunAddr1); 201 CreateStunPort(kStunAddr1);
196 PrepareAddress(); 202 PrepareAddress();
197 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 203 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
198 ASSERT_EQ(1U, port()->Candidates().size()); 204 ASSERT_EQ(1U, port()->Candidates().size());
199 EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); 205 EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
200 206
201 // TODO: Add IPv6 tests here, once either physicalsocketserver supports 207 // TODO: Add IPv6 tests here, once either physicalsocketserver supports
202 // IPv6, or this test is changed to use VirtualSocketServer. 208 // IPv6, or this test is changed to use VirtualSocketServer.
203 } 209 }
204 210
205 // Test that we fail properly if we can't get an address. 211 // Test that we fail properly if we can't get an address.
206 TEST_F(StunPortTest, TestPrepareAddressFail) { 212 TEST_F(StunPortTest, TestPrepareAddressFail) {
207 CreateStunPort(kBadAddr); 213 CreateStunPort(kBadAddr);
208 PrepareAddress(); 214 PrepareAddress();
209 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 215 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
210 EXPECT_TRUE(error()); 216 EXPECT_TRUE(error());
211 EXPECT_EQ(0U, port()->Candidates().size()); 217 EXPECT_EQ(0U, port()->Candidates().size());
212 } 218 }
213 219
214 // Test that we can get an address from a STUN server specified by a hostname. 220 // Test that we can get an address from a STUN server specified by a hostname.
215 TEST_F(StunPortTest, TestPrepareAddressHostname) { 221 TEST_F(StunPortTest, TestPrepareAddressHostname) {
216 CreateStunPort(kStunHostnameAddr); 222 CreateStunPort(kStunHostnameAddr);
217 PrepareAddress(); 223 PrepareAddress();
218 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 224 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
219 ASSERT_EQ(1U, port()->Candidates().size()); 225 ASSERT_EQ(1U, port()->Candidates().size());
220 EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); 226 EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
221 EXPECT_EQ(kStunCandidatePriority, port()->Candidates()[0].priority()); 227 EXPECT_EQ(kStunCandidatePriority, port()->Candidates()[0].priority());
222 } 228 }
223 229
224 // Test that we handle hostname lookup failures properly. 230 // Test that we handle hostname lookup failures properly.
225 TEST_F(StunPortTest, TestPrepareAddressHostnameFail) { 231 TEST_F(StunPortTestWithRealClock, TestPrepareAddressHostnameFail) {
226 CreateStunPort(kBadHostnameAddr); 232 CreateStunPort(kBadHostnameAddr);
227 PrepareAddress(); 233 PrepareAddress();
228 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 234 EXPECT_TRUE_WAIT(done(), kTimeoutMs);
229 EXPECT_TRUE(error()); 235 EXPECT_TRUE(error());
230 EXPECT_EQ(0U, port()->Candidates().size()); 236 EXPECT_EQ(0U, port()->Candidates().size());
231 } 237 }
232 238
233 // This test verifies keepalive response messages don't result in 239 // This test verifies keepalive response messages don't result in
234 // additional candidate generation. 240 // additional candidate generation.
235 TEST_F(StunPortTest, TestKeepAliveResponse) { 241 TEST_F(StunPortTest, TestKeepAliveResponse) {
236 SetKeepaliveDelay(500); // 500ms of keepalive delay. 242 SetKeepaliveDelay(500); // 500ms of keepalive delay.
237 CreateStunPort(kStunHostnameAddr); 243 CreateStunPort(kStunHostnameAddr);
238 PrepareAddress(); 244 PrepareAddress();
239 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 245 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
240 ASSERT_EQ(1U, port()->Candidates().size()); 246 ASSERT_EQ(1U, port()->Candidates().size());
241 EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); 247 EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
242 // Waiting for 1 seond, which will allow us to process 248 SIMULATED_WAIT(false, 1000, fake_clock);
243 // response for keepalive binding request. 500 ms is the keepalive delay. 249 EXPECT_EQ(1U, port()->Candidates().size());
244 rtc::Thread::Current()->ProcessMessages(1000);
245 ASSERT_EQ(1U, port()->Candidates().size());
246 } 250 }
247 251
248 // Test that a local candidate can be generated using a shared socket. 252 // Test that a local candidate can be generated using a shared socket.
249 TEST_F(StunPortTest, TestSharedSocketPrepareAddress) { 253 TEST_F(StunPortTest, TestSharedSocketPrepareAddress) {
250 CreateSharedUdpPort(kStunAddr1); 254 CreateSharedUdpPort(kStunAddr1);
251 PrepareAddress(); 255 PrepareAddress();
252 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 256 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
253 ASSERT_EQ(1U, port()->Candidates().size()); 257 ASSERT_EQ(1U, port()->Candidates().size());
254 EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); 258 EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
255 } 259 }
256 260
257 // Test that we still a get a local candidate with invalid stun server hostname. 261 // Test that we still a get a local candidate with invalid stun server hostname.
258 // Also verifing that UDPPort can receive packets when stun address can't be 262 // Also verifing that UDPPort can receive packets when stun address can't be
259 // resolved. 263 // resolved.
260 TEST_F(StunPortTest, TestSharedSocketPrepareAddressInvalidHostname) { 264 TEST_F(StunPortTestWithRealClock,
265 TestSharedSocketPrepareAddressInvalidHostname) {
261 CreateSharedUdpPort(kBadHostnameAddr); 266 CreateSharedUdpPort(kBadHostnameAddr);
262 PrepareAddress(); 267 PrepareAddress();
263 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 268 EXPECT_TRUE_WAIT(done(), kTimeoutMs);
264 ASSERT_EQ(1U, port()->Candidates().size()); 269 ASSERT_EQ(1U, port()->Candidates().size());
265 EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); 270 EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
266 271
267 // Send data to port after it's ready. This is to make sure, UDP port can 272 // Send data to port after it's ready. This is to make sure, UDP port can
268 // handle data with unresolved stun server address. 273 // handle data with unresolved stun server address.
269 std::string data = "some random data, sending to cricket::Port."; 274 std::string data = "some random data, sending to cricket::Port.";
270 SendData(data.c_str(), data.length()); 275 SendData(data.c_str(), data.length());
271 // No crash is success. 276 // No crash is success.
272 } 277 }
273 278
274 // Test that the same address is added only once if two STUN servers are in use. 279 // Test that the same address is added only once if two STUN servers are in use.
275 TEST_F(StunPortTest, TestNoDuplicatedAddressWithTwoStunServers) { 280 TEST_F(StunPortTest, TestNoDuplicatedAddressWithTwoStunServers) {
276 ServerAddresses stun_servers; 281 ServerAddresses stun_servers;
277 stun_servers.insert(kStunAddr1); 282 stun_servers.insert(kStunAddr1);
278 stun_servers.insert(kStunAddr2); 283 stun_servers.insert(kStunAddr2);
279 CreateStunPort(stun_servers); 284 CreateStunPort(stun_servers);
280 EXPECT_EQ("stun", port()->Type()); 285 EXPECT_EQ("stun", port()->Type());
281 PrepareAddress(); 286 PrepareAddress();
282 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 287 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
283 EXPECT_EQ(1U, port()->Candidates().size()); 288 EXPECT_EQ(1U, port()->Candidates().size());
284 EXPECT_EQ(port()->Candidates()[0].relay_protocol(), ""); 289 EXPECT_EQ(port()->Candidates()[0].relay_protocol(), "");
285 } 290 }
286 291
287 // Test that candidates can be allocated for multiple STUN servers, one of which 292 // Test that candidates can be allocated for multiple STUN servers, one of which
288 // is not reachable. 293 // is not reachable.
289 TEST_F(StunPortTest, TestMultipleStunServersWithBadServer) { 294 TEST_F(StunPortTest, TestMultipleStunServersWithBadServer) {
290 ServerAddresses stun_servers; 295 ServerAddresses stun_servers;
291 stun_servers.insert(kStunAddr1); 296 stun_servers.insert(kStunAddr1);
292 stun_servers.insert(kBadAddr); 297 stun_servers.insert(kBadAddr);
293 CreateStunPort(stun_servers); 298 CreateStunPort(stun_servers);
294 EXPECT_EQ("stun", port()->Type()); 299 EXPECT_EQ("stun", port()->Type());
295 PrepareAddress(); 300 PrepareAddress();
296 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 301 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
297 EXPECT_EQ(1U, port()->Candidates().size()); 302 EXPECT_EQ(1U, port()->Candidates().size());
298 } 303 }
299 304
300 // Test that two candidates are allocated if the two STUN servers return 305 // Test that two candidates are allocated if the two STUN servers return
301 // different mapped addresses. 306 // different mapped addresses.
302 TEST_F(StunPortTest, TestTwoCandidatesWithTwoStunServersAcrossNat) { 307 TEST_F(StunPortTest, TestTwoCandidatesWithTwoStunServersAcrossNat) {
303 const SocketAddress kStunMappedAddr1("77.77.77.77", 0); 308 const SocketAddress kStunMappedAddr1("77.77.77.77", 0);
304 const SocketAddress kStunMappedAddr2("88.77.77.77", 0); 309 const SocketAddress kStunMappedAddr2("88.77.77.77", 0);
305 stun_server_1()->set_fake_stun_addr(kStunMappedAddr1); 310 stun_server_1()->set_fake_stun_addr(kStunMappedAddr1);
306 stun_server_2()->set_fake_stun_addr(kStunMappedAddr2); 311 stun_server_2()->set_fake_stun_addr(kStunMappedAddr2);
307 312
308 ServerAddresses stun_servers; 313 ServerAddresses stun_servers;
309 stun_servers.insert(kStunAddr1); 314 stun_servers.insert(kStunAddr1);
310 stun_servers.insert(kStunAddr2); 315 stun_servers.insert(kStunAddr2);
311 CreateStunPort(stun_servers); 316 CreateStunPort(stun_servers);
312 EXPECT_EQ("stun", port()->Type()); 317 EXPECT_EQ("stun", port()->Type());
313 PrepareAddress(); 318 PrepareAddress();
314 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 319 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
315 EXPECT_EQ(2U, port()->Candidates().size()); 320 EXPECT_EQ(2U, port()->Candidates().size());
316 EXPECT_EQ(port()->Candidates()[0].relay_protocol(), ""); 321 EXPECT_EQ(port()->Candidates()[0].relay_protocol(), "");
317 EXPECT_EQ(port()->Candidates()[1].relay_protocol(), ""); 322 EXPECT_EQ(port()->Candidates()[1].relay_protocol(), "");
318 } 323 }
319 324
320 // Test that the stun_keepalive_lifetime is set correctly based on the network 325 // Test that the stun_keepalive_lifetime is set correctly based on the network
321 // type on a STUN port. Also test that it will be updated if the network type 326 // type on a STUN port. Also test that it will be updated if the network type
322 // changes. 327 // changes.
323 TEST_F(StunPortTest, TestStunPortGetStunKeepaliveLifetime) { 328 TEST_F(StunPortTest, TestStunPortGetStunKeepaliveLifetime) {
324 // Lifetime for the default (unknown) network type is |kInfiniteLifetime|. 329 // Lifetime for the default (unknown) network type is |kInfiniteLifetime|.
(...skipping 28 matching lines...) Expand all
353 EXPECT_EQ(kInfiniteLifetime, port()->stun_keepalive_lifetime()); 358 EXPECT_EQ(kInfiniteLifetime, port()->stun_keepalive_lifetime());
354 } 359 }
355 360
356 // Test that STUN binding requests will be stopped shortly if the keep-alive 361 // Test that STUN binding requests will be stopped shortly if the keep-alive
357 // lifetime is short. 362 // lifetime is short.
358 TEST_F(StunPortTest, TestStunBindingRequestShortLifetime) { 363 TEST_F(StunPortTest, TestStunBindingRequestShortLifetime) {
359 SetKeepaliveDelay(101); 364 SetKeepaliveDelay(101);
360 SetKeepaliveLifetime(100); 365 SetKeepaliveLifetime(100);
361 CreateStunPort(kStunAddr1); 366 CreateStunPort(kStunAddr1);
362 PrepareAddress(); 367 PrepareAddress();
363 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 368 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
364 EXPECT_TRUE_WAIT(!port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST), 369 EXPECT_TRUE_SIMULATED_WAIT(
365 2000); 370 !port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST), 2000,
371 fake_clock);
366 } 372 }
367 373
368 // Test that by default, the STUN binding requests will last for a long time. 374 // Test that by default, the STUN binding requests will last for a long time.
369 TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) { 375 TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) {
370 SetKeepaliveDelay(101); 376 SetKeepaliveDelay(101);
371 CreateStunPort(kStunAddr1); 377 CreateStunPort(kStunAddr1);
372 PrepareAddress(); 378 PrepareAddress();
373 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 379 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
374 rtc::Thread::Current()->ProcessMessages(1000); 380 EXPECT_TRUE_SIMULATED_WAIT(
375 EXPECT_TRUE(port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST)); 381 port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST), 1000,
382 fake_clock);
376 } 383 }
OLDNEW
« no previous file with comments | « webrtc/base/signalthread.cc ('k') | webrtc/p2p/client/basicportallocator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698