Chromium Code Reviews| 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 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 StunMessage* msg = new StunMessage(); | 50 StunMessage* msg = new StunMessage(); |
| 51 msg->SetType(type); | 51 msg->SetType(type); |
| 52 if (req) { | 52 if (req) { |
| 53 msg->SetTransactionID(req->transaction_id()); | 53 msg->SetTransactionID(req->transaction_id()); |
| 54 } | 54 } |
| 55 return msg; | 55 return msg; |
| 56 } | 56 } |
| 57 static int TotalDelay(int sends) { | 57 static int TotalDelay(int sends) { |
| 58 int total = 0; | 58 int total = 0; |
| 59 for (int i = 0; i < sends; i++) { | 59 for (int i = 0; i < sends; i++) { |
| 60 if (i < 4) | 60 if (i < 5) |
| 61 total += 100 << i; | 61 total += 250 << i; |
|
skvlad
2017/02/07 03:05:45
could it be more clear with a hardcoded array?
st
| |
| 62 else | 62 else |
| 63 total += 1600; | 63 total += 8000; |
| 64 } | 64 } |
| 65 return total; | 65 return total; |
| 66 } | 66 } |
| 67 | 67 |
| 68 StunRequestManager manager_; | 68 StunRequestManager manager_; |
| 69 int request_count_; | 69 int request_count_; |
| 70 StunMessage* response_; | 70 StunMessage* response_; |
| 71 bool success_; | 71 bool success_; |
| 72 bool failure_; | 72 bool failure_; |
| 73 bool timeout_; | 73 bool timeout_; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 EXPECT_FALSE(manager_.CheckResponse(res)); | 136 EXPECT_FALSE(manager_.CheckResponse(res)); |
| 137 | 137 |
| 138 EXPECT_TRUE(response_ == NULL); | 138 EXPECT_TRUE(response_ == NULL); |
| 139 EXPECT_FALSE(success_); | 139 EXPECT_FALSE(success_); |
| 140 EXPECT_FALSE(failure_); | 140 EXPECT_FALSE(failure_); |
| 141 EXPECT_FALSE(timeout_); | 141 EXPECT_FALSE(timeout_); |
| 142 delete res; | 142 delete res; |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Test that requests are sent at the right times, and that the 9th request | 145 // Test that requests are sent at the right times, and that the 9th request |
| 146 // (sent at 7900 ms) can be properly replied to. | 146 // (sent at 32000 ms) can be properly replied to. |
| 147 TEST_F(StunRequestTest, TestBackoff) { | 147 TEST_F(StunRequestTest, TestBackoff) { |
| 148 const int MAX_TIMEOUT_MS = 10000; | |
| 149 rtc::ScopedFakeClock fake_clock; | 148 rtc::ScopedFakeClock fake_clock; |
| 150 StunMessage* req = CreateStunMessage(STUN_BINDING_REQUEST, NULL); | 149 StunMessage* req = CreateStunMessage(STUN_BINDING_REQUEST, NULL); |
| 151 | 150 |
| 152 int64_t start = rtc::TimeMillis(); | 151 int64_t start = rtc::TimeMillis(); |
| 153 manager_.Send(new StunRequestThunker(req, this)); | 152 manager_.Send(new StunRequestThunker(req, this)); |
| 154 StunMessage* res = CreateStunMessage(STUN_BINDING_RESPONSE, req); | 153 StunMessage* res = CreateStunMessage(STUN_BINDING_RESPONSE, req); |
| 155 for (int i = 0; i < 9; ++i) { | 154 for (int i = 0; i < 9; ++i) { |
| 156 EXPECT_TRUE_SIMULATED_WAIT(request_count_ != i, MAX_TIMEOUT_MS, fake_clock); | 155 EXPECT_TRUE_SIMULATED_WAIT(request_count_ != i, STUN_TOTAL_TIMEOUT, |
| 156 fake_clock); | |
| 157 int64_t elapsed = rtc::TimeMillis() - start; | 157 int64_t elapsed = rtc::TimeMillis() - start; |
| 158 LOG(LS_INFO) << "STUN request #" << (i + 1) | 158 LOG(LS_INFO) << "STUN request #" << (i + 1) |
| 159 << " sent at " << elapsed << " ms"; | 159 << " sent at " << elapsed << " ms"; |
| 160 EXPECT_EQ(TotalDelay(i), elapsed); | 160 EXPECT_EQ(TotalDelay(i), elapsed); |
| 161 } | 161 } |
| 162 EXPECT_TRUE(manager_.CheckResponse(res)); | 162 EXPECT_TRUE(manager_.CheckResponse(res)); |
| 163 | 163 |
| 164 EXPECT_TRUE(response_ == res); | 164 EXPECT_TRUE(response_ == res); |
| 165 EXPECT_TRUE(success_); | 165 EXPECT_TRUE(success_); |
| 166 EXPECT_FALSE(failure_); | 166 EXPECT_FALSE(failure_); |
| 167 EXPECT_FALSE(timeout_); | 167 EXPECT_FALSE(timeout_); |
| 168 delete res; | 168 delete res; |
| 169 } | 169 } |
| 170 | 170 |
| 171 // Test that we timeout properly if no response is received in 9500 ms. | 171 // Test that we timeout properly if no response is received in 40000 ms. |
| 172 TEST_F(StunRequestTest, TestTimeout) { | 172 TEST_F(StunRequestTest, TestTimeout) { |
| 173 rtc::ScopedFakeClock fake_clock; | 173 rtc::ScopedFakeClock fake_clock; |
| 174 StunMessage* req = CreateStunMessage(STUN_BINDING_REQUEST, NULL); | 174 StunMessage* req = CreateStunMessage(STUN_BINDING_REQUEST, NULL); |
| 175 StunMessage* res = CreateStunMessage(STUN_BINDING_RESPONSE, req); | 175 StunMessage* res = CreateStunMessage(STUN_BINDING_RESPONSE, req); |
| 176 | 176 |
| 177 manager_.Send(new StunRequestThunker(req, this)); | 177 manager_.Send(new StunRequestThunker(req, this)); |
| 178 // Simulate the 9500 ms STUN timeout | 178 SIMULATED_WAIT(false, cricket::STUN_TOTAL_TIMEOUT, fake_clock); |
| 179 SIMULATED_WAIT(false, 9500, fake_clock); | |
| 180 | 179 |
| 181 EXPECT_FALSE(manager_.CheckResponse(res)); | 180 EXPECT_FALSE(manager_.CheckResponse(res)); |
| 182 EXPECT_TRUE(response_ == NULL); | 181 EXPECT_TRUE(response_ == NULL); |
| 183 EXPECT_FALSE(success_); | 182 EXPECT_FALSE(success_); |
| 184 EXPECT_FALSE(failure_); | 183 EXPECT_FALSE(failure_); |
| 185 EXPECT_TRUE(timeout_); | 184 EXPECT_TRUE(timeout_); |
| 186 delete res; | 185 delete res; |
| 187 } | 186 } |
| 188 | 187 |
| 189 // Regression test for specific crash where we receive a response with the | 188 // Regression test for specific crash where we receive a response with the |
| 190 // same id as a request that doesn't have an underlying StunMessage yet. | 189 // same id as a request that doesn't have an underlying StunMessage yet. |
| 191 TEST_F(StunRequestTest, TestNoEmptyRequest) { | 190 TEST_F(StunRequestTest, TestNoEmptyRequest) { |
| 192 StunRequestThunker* request = new StunRequestThunker(this); | 191 StunRequestThunker* request = new StunRequestThunker(this); |
| 193 | 192 |
| 194 manager_.SendDelayed(request, 100); | 193 manager_.SendDelayed(request, 100); |
| 195 | 194 |
| 196 StunMessage dummy_req; | 195 StunMessage dummy_req; |
| 197 dummy_req.SetTransactionID(request->id()); | 196 dummy_req.SetTransactionID(request->id()); |
| 198 StunMessage* res = CreateStunMessage(STUN_BINDING_RESPONSE, &dummy_req); | 197 StunMessage* res = CreateStunMessage(STUN_BINDING_RESPONSE, &dummy_req); |
| 199 | 198 |
| 200 EXPECT_TRUE(manager_.CheckResponse(res)); | 199 EXPECT_TRUE(manager_.CheckResponse(res)); |
| 201 | 200 |
| 202 EXPECT_TRUE(response_ == res); | 201 EXPECT_TRUE(response_ == res); |
| 203 EXPECT_TRUE(success_); | 202 EXPECT_TRUE(success_); |
| 204 EXPECT_FALSE(failure_); | 203 EXPECT_FALSE(failure_); |
| 205 EXPECT_FALSE(timeout_); | 204 EXPECT_FALSE(timeout_); |
| 206 delete res; | 205 delete res; |
| 207 } | 206 } |
| OLD | NEW |