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/base/backoff_entry.h" | 5 #include "net/base/backoff_entry.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 namespace { | 8 namespace { |
9 | 9 |
10 using base::TimeDelta; | 10 using base::TimeDelta; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 // Regression test for a bug discovered during code review. | 286 // Regression test for a bug discovered during code review. |
287 BackoffEntry::Policy lenient_policy = base_policy; | 287 BackoffEntry::Policy lenient_policy = base_policy; |
288 lenient_policy.num_errors_to_ignore = 1; | 288 lenient_policy.num_errors_to_ignore = 1; |
289 TestBackoffEntry custom(&lenient_policy); | 289 TestBackoffEntry custom(&lenient_policy); |
290 TimeTicks custom_horizon = TimeTicks() + TimeDelta::FromDays(3); | 290 TimeTicks custom_horizon = TimeTicks() + TimeDelta::FromDays(3); |
291 custom.SetCustomReleaseTime(custom_horizon); | 291 custom.SetCustomReleaseTime(custom_horizon); |
292 custom.InformOfRequest(false); // This must not reset the horizon. | 292 custom.InformOfRequest(false); // This must not reset the horizon. |
293 EXPECT_EQ(custom_horizon, custom.GetReleaseTime()); | 293 EXPECT_EQ(custom_horizon, custom.GetReleaseTime()); |
294 } | 294 } |
295 | 295 |
| 296 TEST(BackoffEntryTest, OverflowProtection) { |
| 297 BackoffEntry::Policy large_multiply_policy = base_policy; |
| 298 large_multiply_policy.multiply_factor = 256; |
| 299 TestBackoffEntry custom(&large_multiply_policy); |
| 300 |
| 301 // Trigger enough failures such that more than 11 bits of exponent are used |
| 302 // to represent the exponential backoff intermediate values. Given a multiply |
| 303 // factor of 256 (2^8), 129 iterations is enough: 2^(8*(129-1)) = 2^1024. |
| 304 for (int i = 0; i < 129; ++i) { |
| 305 custom.set_now(custom.ImplGetTimeNow() + custom.GetTimeUntilRelease()); |
| 306 custom.InformOfRequest(false); |
| 307 ASSERT_TRUE(custom.ShouldRejectRequest()); |
| 308 } |
| 309 |
| 310 // Max delay should still be respected. |
| 311 EXPECT_EQ(20000, custom.GetTimeUntilRelease().InMilliseconds()); |
| 312 } |
| 313 |
296 } // namespace | 314 } // namespace |
OLD | NEW |