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 // The tests in this file attempt to verify the following through simulation: | 5 // The tests in this file attempt to verify the following through simulation: |
6 // a) That a server experiencing overload will actually benefit from the | 6 // a) That a server experiencing overload will actually benefit from the |
7 // anti-DDoS throttling logic, i.e. that its traffic spike will subside | 7 // anti-DDoS throttling logic, i.e. that its traffic spike will subside |
8 // and be distributed over a longer period of time; | 8 // and be distributed over a longer period of time; |
9 // b) That "well-behaved" clients of a server under DDoS attack actually | 9 // b) That "well-behaved" clients of a server under DDoS attack actually |
10 // benefit from the anti-DDoS throttling logic; and | 10 // benefit from the anti-DDoS throttling logic; and |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 290 |
291 TestURLRequestContext context_; | 291 TestURLRequestContext context_; |
292 TestURLRequest mock_request_; | 292 TestURLRequest mock_request_; |
293 | 293 |
294 DISALLOW_COPY_AND_ASSIGN(Server); | 294 DISALLOW_COPY_AND_ASSIGN(Server); |
295 }; | 295 }; |
296 | 296 |
297 // Mock throttler entry used by Requester class. | 297 // Mock throttler entry used by Requester class. |
298 class MockURLRequestThrottlerEntry : public URLRequestThrottlerEntry { | 298 class MockURLRequestThrottlerEntry : public URLRequestThrottlerEntry { |
299 public: | 299 public: |
300 explicit MockURLRequestThrottlerEntry( | 300 explicit MockURLRequestThrottlerEntry(URLRequestThrottlerManager* manager) |
301 URLRequestThrottlerManager* manager) | 301 : URLRequestThrottlerEntry(manager, std::string()), |
302 : URLRequestThrottlerEntry(manager, ""), | 302 mock_backoff_entry_(&backoff_policy_) {} |
303 mock_backoff_entry_(&backoff_policy_) { | |
304 } | |
305 | 303 |
306 virtual const BackoffEntry* GetBackoffEntry() const OVERRIDE { | 304 virtual const BackoffEntry* GetBackoffEntry() const OVERRIDE { |
307 return &mock_backoff_entry_; | 305 return &mock_backoff_entry_; |
308 } | 306 } |
309 | 307 |
310 virtual BackoffEntry* GetBackoffEntry() OVERRIDE { | 308 virtual BackoffEntry* GetBackoffEntry() OVERRIDE { |
311 return &mock_backoff_entry_; | 309 return &mock_backoff_entry_; |
312 } | 310 } |
313 | 311 |
314 virtual TimeTicks ImplGetTimeNow() const OVERRIDE { | 312 virtual TimeTicks ImplGetTimeNow() const OVERRIDE { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 effective_delay -= current_jitter; | 424 effective_delay -= current_jitter; |
427 } else { | 425 } else { |
428 effective_delay += current_jitter; | 426 effective_delay += current_jitter; |
429 } | 427 } |
430 | 428 |
431 if (throttler_entry_->fake_now() - time_of_last_attempt_ > | 429 if (throttler_entry_->fake_now() - time_of_last_attempt_ > |
432 effective_delay) { | 430 effective_delay) { |
433 if (!throttler_entry_->ShouldRejectRequest(server_->mock_request())) { | 431 if (!throttler_entry_->ShouldRejectRequest(server_->mock_request())) { |
434 int status_code = server_->HandleRequest(); | 432 int status_code = server_->HandleRequest(); |
435 MockURLRequestThrottlerHeaderAdapter response_headers(status_code); | 433 MockURLRequestThrottlerHeaderAdapter response_headers(status_code); |
436 throttler_entry_->UpdateWithResponse("", &response_headers); | 434 throttler_entry_->UpdateWithResponse(std::string(), &response_headers); |
437 | 435 |
438 if (status_code == 200) { | 436 if (status_code == 200) { |
439 if (results_) | 437 if (results_) |
440 results_->AddSuccess(); | 438 results_->AddSuccess(); |
441 | 439 |
442 if (last_attempt_was_failure_) { | 440 if (last_attempt_was_failure_) { |
443 last_downtime_duration_ = | 441 last_downtime_duration_ = |
444 throttler_entry_->fake_now() - time_of_last_success_; | 442 throttler_entry_->fake_now() - time_of_last_success_; |
445 } | 443 } |
446 | 444 |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 trials[i].PrintTrialDescription(); | 746 trials[i].PrintTrialDescription(); |
749 trials[i].stats.ReportTrialResult(increase_ratio); | 747 trials[i].stats.ReportTrialResult(increase_ratio); |
750 } | 748 } |
751 | 749 |
752 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); | 750 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); |
753 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); | 751 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); |
754 } | 752 } |
755 | 753 |
756 } // namespace | 754 } // namespace |
757 } // namespace net | 755 } // namespace net |
OLD | NEW |