Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/message_loop_proxy.h" | 6 #include "base/message_loop_proxy.h" |
| 7 #include "base/ref_counted.h" | 7 #include "base/ref_counted.h" |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "chrome/common/net/url_request_context_getter.h" | 10 #include "chrome/common/net/url_request_context_getter.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 CloudPrintURLFetcherRetryBackoffTest::HandleRawData(const URLFetcher* source, | 278 CloudPrintURLFetcherRetryBackoffTest::HandleRawData(const URLFetcher* source, |
| 279 const GURL& url, | 279 const GURL& url, |
| 280 const std::string& data) { | 280 const std::string& data) { |
| 281 response_count_++; | 281 response_count_++; |
| 282 // First attempt + 11 retries = 12 total responses. | 282 // First attempt + 11 retries = 12 total responses. |
| 283 EXPECT_LE(response_count_, 12); | 283 EXPECT_LE(response_count_, 12); |
| 284 return CloudPrintURLFetcher::RETRY_REQUEST; | 284 return CloudPrintURLFetcher::RETRY_REQUEST; |
| 285 } | 285 } |
| 286 | 286 |
| 287 void CloudPrintURLFetcherRetryBackoffTest::OnRequestGiveUp() { | 287 void CloudPrintURLFetcherRetryBackoffTest::OnRequestGiveUp() { |
| 288 const TimeDelta one_second = TimeDelta::FromMilliseconds(1000); | 288 // It takes more than 200 ms to finish all 11 requests. |
| 289 // It takes more than 1 second to finish all 11 requests. | 289 EXPECT_TRUE(Time::Now() - start_time_ >= TimeDelta::FromMilliseconds(200)); |
|
wtc
2011/03/25 19:06:24
Just curious: is one second too long? How do we c
Jói
2011/03/25 21:26:51
It's dependent on the default exponential back-off
| |
| 290 EXPECT_TRUE(Time::Now() - start_time_ >= one_second); | |
| 291 io_message_loop_proxy()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 290 io_message_loop_proxy()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 292 } | 291 } |
| 293 | 292 |
| 294 // http://code.google.com/p/chromium/issues/detail?id=60426 | 293 // http://code.google.com/p/chromium/issues/detail?id=60426 |
| 295 TEST_F(CloudPrintURLFetcherBasicTest, FLAKY_HandleRawResponse) { | 294 TEST_F(CloudPrintURLFetcherBasicTest, FLAKY_HandleRawResponse) { |
| 296 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 295 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); |
| 297 ASSERT_TRUE(test_server.Start()); | 296 ASSERT_TRUE(test_server.Start()); |
| 298 SetHandleRawResponse(true); | 297 SetHandleRawResponse(true); |
| 299 | 298 |
| 300 CreateFetcher(test_server.GetURL("echo"), 0); | 299 CreateFetcher(test_server.GetURL("echo"), 0); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 312 } | 311 } |
| 313 | 312 |
| 314 TEST_F(CloudPrintURLFetcherOverloadTest, Protect) { | 313 TEST_F(CloudPrintURLFetcherOverloadTest, Protect) { |
| 315 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 314 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); |
| 316 ASSERT_TRUE(test_server.Start()); | 315 ASSERT_TRUE(test_server.Start()); |
| 317 | 316 |
| 318 GURL url(test_server.GetURL("defaultresponse")); | 317 GURL url(test_server.GetURL("defaultresponse")); |
| 319 | 318 |
| 320 // Registers an entry for test url. It only allows 3 requests to be sent | 319 // Registers an entry for test url. It only allows 3 requests to be sent |
| 321 // in 200 milliseconds. | 320 // in 200 milliseconds. |
| 321 net::URLRequestThrottlerManager* manager = | |
| 322 net::URLRequestThrottlerManager::GetInstance(); | |
| 322 scoped_refptr<net::URLRequestThrottlerEntry> entry( | 323 scoped_refptr<net::URLRequestThrottlerEntry> entry( |
| 323 new net::URLRequestThrottlerEntry(200, 3, 1, 2.0, 0.0, 256)); | 324 new net::URLRequestThrottlerEntry(manager, 200, 3, 1, 2.0, 0.0, 256)); |
| 324 net::URLRequestThrottlerManager::GetInstance()->OverrideEntryForTests( | 325 manager->OverrideEntryForTests(url, entry); |
| 325 url, entry); | |
| 326 | 326 |
| 327 CreateFetcher(url, 11); | 327 CreateFetcher(url, 11); |
| 328 | 328 |
| 329 MessageLoop::current()->Run(); | 329 MessageLoop::current()->Run(); |
| 330 | 330 |
| 331 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); | 331 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); |
| 332 } | 332 } |
| 333 | 333 |
| 334 // http://code.google.com/p/chromium/issues/detail?id=60426 | 334 // http://code.google.com/p/chromium/issues/detail?id=60426 |
| 335 TEST_F(CloudPrintURLFetcherRetryBackoffTest, FLAKY_GiveUp) { | 335 TEST_F(CloudPrintURLFetcherRetryBackoffTest, FLAKY_GiveUp) { |
| 336 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 336 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); |
| 337 ASSERT_TRUE(test_server.Start()); | 337 ASSERT_TRUE(test_server.Start()); |
| 338 | 338 |
| 339 GURL url(test_server.GetURL("defaultresponse")); | 339 GURL url(test_server.GetURL("defaultresponse")); |
| 340 | 340 |
| 341 // Registers an entry for test url. The backoff time is calculated by: | 341 // Registers an entry for test url. The backoff time is calculated by: |
| 342 // new_backoff = 2.0 * old_backoff + 0 | 342 // new_backoff = 2.0 * old_backoff + 0 |
| 343 // and maximum backoff time is 256 milliseconds. | 343 // and maximum backoff time is 256 milliseconds. |
| 344 // Maximum retries allowed is set to 11. | 344 // Maximum retries allowed is set to 11. |
| 345 net::URLRequestThrottlerManager* manager = | |
| 346 net::URLRequestThrottlerManager::GetInstance(); | |
| 345 scoped_refptr<net::URLRequestThrottlerEntry> entry( | 347 scoped_refptr<net::URLRequestThrottlerEntry> entry( |
| 346 new net::URLRequestThrottlerEntry(200, 3, 1, 2.0, 0.0, 256)); | 348 new net::URLRequestThrottlerEntry(manager, 200, 3, 1, 2.0, 0.0, 256)); |
| 347 net::URLRequestThrottlerManager::GetInstance()->OverrideEntryForTests( | 349 manager->OverrideEntryForTests(url, entry); |
| 348 url, entry); | |
| 349 | 350 |
| 350 CreateFetcher(url, 11); | 351 CreateFetcher(url, 11); |
| 351 | 352 |
| 352 MessageLoop::current()->Run(); | 353 MessageLoop::current()->Run(); |
| 353 | 354 |
| 354 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); | 355 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); |
| 355 } | 356 } |
| 356 | 357 |
| 357 } // namespace. | 358 } // namespace. |
| OLD | NEW |