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 TestBackoffEntry custom(&base_policy); | |
298 | |
299 // Trigger enough failures such that more than 11 bits of exponent are used | |
300 // to represent the exponential backoff intermediate values. | |
cbentzel
2014/06/14 15:16:07
Could you use a different policy for this test wit
Nicolas Zea
2014/06/16 20:27:25
Done.
| |
301 for (size_t i = 0; i < (1 << 11); ++i) { | |
302 custom.set_now(custom.ImplGetTimeNow() + custom.GetTimeUntilRelease()); | |
303 custom.InformOfRequest(false); | |
304 EXPECT_TRUE(custom.ShouldRejectRequest()); | |
305 } | |
306 | |
307 // Max delay should still be respected. | |
308 EXPECT_EQ(20000, custom.GetTimeUntilRelease().InMilliseconds()); | |
309 } | |
310 | |
296 } // namespace | 311 } // namespace |
OLD | NEW |