| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 |
| 11 #include "webrtc/p2p/base/stunrequest.h" | 11 #include "webrtc/p2p/base/stunrequest.h" |
| 12 #include "webrtc/base/gunit.h" | 12 #include "webrtc/base/gunit.h" |
| 13 #include "webrtc/base/helpers.h" | 13 #include "webrtc/base/helpers.h" |
| 14 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
| 15 #include "webrtc/base/ssladapter.h" | 15 #include "webrtc/base/ssladapter.h" |
| 16 #include "webrtc/base/timeutils.h" | 16 #include "webrtc/base/timeutils.h" |
| 17 | 17 |
| 18 using namespace cricket; | 18 using namespace cricket; |
| 19 | 19 |
| 20 // STUN timeout (with all retries) is 9500ms. |
| 21 // Add some margin of error for slow bots. |
| 22 // TODO(deadbeef): Use simulated clock instead of just increasing timeouts to |
| 23 // fix flaky tests. |
| 24 static const int kTimeoutMs = 15000; |
| 25 |
| 20 class StunRequestTest : public testing::Test, | 26 class StunRequestTest : public testing::Test, |
| 21 public sigslot::has_slots<> { | 27 public sigslot::has_slots<> { |
| 22 public: | 28 public: |
| 23 StunRequestTest() | 29 StunRequestTest() |
| 24 : manager_(rtc::Thread::Current()), | 30 : manager_(rtc::Thread::Current()), |
| 25 request_count_(0), response_(NULL), | 31 request_count_(0), response_(NULL), |
| 26 success_(false), failure_(false), timeout_(false) { | 32 success_(false), failure_(false), timeout_(false) { |
| 27 manager_.SignalSendPacket.connect(this, &StunRequestTest::OnSendPacket); | 33 manager_.SignalSendPacket.connect(this, &StunRequestTest::OnSendPacket); |
| 28 } | 34 } |
| 29 | 35 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 EXPECT_FALSE(timeout_); | 171 EXPECT_FALSE(timeout_); |
| 166 delete res; | 172 delete res; |
| 167 } | 173 } |
| 168 | 174 |
| 169 // Test that we timeout properly if no response is received in 9500 ms. | 175 // Test that we timeout properly if no response is received in 9500 ms. |
| 170 TEST_F(StunRequestTest, TestTimeout) { | 176 TEST_F(StunRequestTest, TestTimeout) { |
| 171 StunMessage* req = CreateStunMessage(STUN_BINDING_REQUEST, NULL); | 177 StunMessage* req = CreateStunMessage(STUN_BINDING_REQUEST, NULL); |
| 172 StunMessage* res = CreateStunMessage(STUN_BINDING_RESPONSE, req); | 178 StunMessage* res = CreateStunMessage(STUN_BINDING_RESPONSE, req); |
| 173 | 179 |
| 174 manager_.Send(new StunRequestThunker(req, this)); | 180 manager_.Send(new StunRequestThunker(req, this)); |
| 175 rtc::Thread::Current()->ProcessMessages(10000); // > STUN timeout | 181 rtc::Thread::Current()->ProcessMessages(kTimeoutMs); |
| 176 EXPECT_FALSE(manager_.CheckResponse(res)); | 182 EXPECT_FALSE(manager_.CheckResponse(res)); |
| 177 | 183 |
| 178 EXPECT_TRUE(response_ == NULL); | 184 EXPECT_TRUE(response_ == NULL); |
| 179 EXPECT_FALSE(success_); | 185 EXPECT_FALSE(success_); |
| 180 EXPECT_FALSE(failure_); | 186 EXPECT_FALSE(failure_); |
| 181 EXPECT_TRUE(timeout_); | 187 EXPECT_TRUE(timeout_); |
| 182 delete res; | 188 delete res; |
| 183 } | 189 } |
| 184 | 190 |
| 185 // Regression test for specific crash where we receive a response with the | 191 // Regression test for specific crash where we receive a response with the |
| 186 // same id as a request that doesn't have an underlying StunMessage yet. | 192 // same id as a request that doesn't have an underlying StunMessage yet. |
| 187 TEST_F(StunRequestTest, TestNoEmptyRequest) { | 193 TEST_F(StunRequestTest, TestNoEmptyRequest) { |
| 188 StunRequestThunker* request = new StunRequestThunker(this); | 194 StunRequestThunker* request = new StunRequestThunker(this); |
| 189 | 195 |
| 190 manager_.SendDelayed(request, 100); | 196 manager_.SendDelayed(request, 100); |
| 191 | 197 |
| 192 StunMessage dummy_req; | 198 StunMessage dummy_req; |
| 193 dummy_req.SetTransactionID(request->id()); | 199 dummy_req.SetTransactionID(request->id()); |
| 194 StunMessage* res = CreateStunMessage(STUN_BINDING_RESPONSE, &dummy_req); | 200 StunMessage* res = CreateStunMessage(STUN_BINDING_RESPONSE, &dummy_req); |
| 195 | 201 |
| 196 EXPECT_TRUE(manager_.CheckResponse(res)); | 202 EXPECT_TRUE(manager_.CheckResponse(res)); |
| 197 | 203 |
| 198 EXPECT_TRUE(response_ == res); | 204 EXPECT_TRUE(response_ == res); |
| 199 EXPECT_TRUE(success_); | 205 EXPECT_TRUE(success_); |
| 200 EXPECT_FALSE(failure_); | 206 EXPECT_FALSE(failure_); |
| 201 EXPECT_FALSE(timeout_); | 207 EXPECT_FALSE(timeout_); |
| 202 delete res; | 208 delete res; |
| 203 } | 209 } |
| OLD | NEW |