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

Side by Side Diff: net/base/backoff_entry_unittest.cc

Issue 337803004: Backoff: Respect maximum delay in face of float overflow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Check max release time too Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/base/backoff_entry.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « net/base/backoff_entry.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698