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

Side by Side Diff: content/browser/loader/resource_scheduler_unittest.cc

Issue 23620058: Add a cap of six in-flight requests per host to the ResourceScheduler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed build Created 7 years, 1 month 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
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 "content/browser/loader/resource_scheduler.h" 5 #include "content/browser/loader/resource_scheduler.h"
6 6
7 #include "base/memory/scoped_vector.h" 7 #include "base/memory/scoped_vector.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "content/browser/browser_thread_impl.h" 10 #include "content/browser/browser_thread_impl.h"
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 311
312 TEST_F(ResourceSchedulerTest, LimitedNumberOfDelayableRequestsInFlight) { 312 TEST_F(ResourceSchedulerTest, LimitedNumberOfDelayableRequestsInFlight) {
313 // We only load low priority resources if there's a body. 313 // We only load low priority resources if there's a body.
314 scheduler_.OnWillInsertBody(kChildId, kRouteId); 314 scheduler_.OnWillInsertBody(kChildId, kRouteId);
315 315
316 // Throw in one high priority request to make sure that's not a factor. 316 // Throw in one high priority request to make sure that's not a factor.
317 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 317 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
318 EXPECT_TRUE(high->started()); 318 EXPECT_TRUE(high->started());
319 319
320 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. 320 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc.
321 ScopedVector<TestRequest> lows; 321 const int kMaxNumDelayableRequestsPerHost = 6;
322 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) { 322 ScopedVector<TestRequest> lows_singlehost;
323 // Queue up to the per-host limit (we subtract the current high-pri request).
324 for (int i = 0; i < kMaxNumDelayableRequestsPerHost - 1; ++i) {
323 string url = "http://host/low" + base::IntToString(i); 325 string url = "http://host/low" + base::IntToString(i);
324 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); 326 lows_singlehost.push_back(NewRequest(url.c_str(), net::LOWEST));
325 EXPECT_TRUE(lows[i]->started()); 327 EXPECT_TRUE(lows_singlehost[i]->started());
326 } 328 }
327 329
328 scoped_ptr<TestRequest> last(NewRequest("http://host/last", net::LOWEST)); 330 scoped_ptr<TestRequest> second_last_singlehost(NewRequest("http://host/last",
329 EXPECT_FALSE(last->started()); 331 net::LOWEST));
James Simonsen 2013/11/13 01:26:23 nit: fix indenting
oystein (OOO til 10th of July) 2013/11/14 00:19:07 Done.
332 scoped_ptr<TestRequest> last_singlehost(NewRequest("http://host/s_last",
333 net::LOWEST));
334
335 EXPECT_FALSE(second_last_singlehost->started());
330 high.reset(); 336 high.reset();
331 EXPECT_FALSE(last->started()); 337 EXPECT_TRUE(second_last_singlehost->started());
332 lows.erase(lows.begin()); 338 EXPECT_FALSE(last_singlehost->started());
333 EXPECT_TRUE(last->started()); 339 lows_singlehost.erase(lows_singlehost.begin());
340 EXPECT_TRUE(last_singlehost->started());
341
342 // Queue more requests from different hosts until we reach the total limit.
343 int expected_slots_left =
344 kMaxNumDelayableRequestsPerClient - kMaxNumDelayableRequestsPerHost;
345 EXPECT_GT(expected_slots_left, 0);
346 ScopedVector<TestRequest> lows_differenthosts;
347 for (int i = 0; i < expected_slots_left; ++i) {
348 string url = "http://host" + base::IntToString(i) + "/low";
349 lows_differenthosts.push_back(NewRequest(url.c_str(), net::LOWEST));
350 EXPECT_TRUE(lows_differenthosts[i]->started());
351 }
352
353 scoped_ptr<TestRequest> last_differenthost(NewRequest("http://host_new/last",
354 net::LOWEST));
James Simonsen 2013/11/13 01:26:23 indent
oystein (OOO til 10th of July) 2013/11/14 00:19:07 Done.
355 EXPECT_FALSE(last_differenthost->started());
334 } 356 }
335 357
336 TEST_F(ResourceSchedulerTest, RaisePriorityAndStart) { 358 TEST_F(ResourceSchedulerTest, RaisePriorityAndStart) {
337 // Dummies to enforce scheduling. 359 // Dummies to enforce scheduling.
338 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 360 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
339 scoped_ptr<TestRequest> low(NewRequest("http://host/req", net::LOWEST)); 361 scoped_ptr<TestRequest> low(NewRequest("http://host/req", net::LOWEST));
340 362
341 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::LOWEST)); 363 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::LOWEST));
342 EXPECT_FALSE(request->started()); 364 EXPECT_FALSE(request->started());
343 365
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 ChangeRequestPriority(request.get(), net::IDLE); 406 ChangeRequestPriority(request.get(), net::IDLE);
385 EXPECT_FALSE(request->started()); 407 EXPECT_FALSE(request->started());
386 EXPECT_FALSE(idle->started()); 408 EXPECT_FALSE(idle->started());
387 409
388 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. 410 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc.
389 // 2 fewer filler requests: 1 for the "low" dummy at the start, and 1 for the 411 // 2 fewer filler requests: 1 for the "low" dummy at the start, and 1 for the
390 // one at the end, which will be tested. 412 // one at the end, which will be tested.
391 const int kNumFillerRequests = kMaxNumDelayableRequestsPerClient - 2; 413 const int kNumFillerRequests = kMaxNumDelayableRequestsPerClient - 2;
392 ScopedVector<TestRequest> lows; 414 ScopedVector<TestRequest> lows;
393 for (int i = 0; i < kNumFillerRequests; ++i) { 415 for (int i = 0; i < kNumFillerRequests; ++i) {
394 string url = "http://host/low" + base::IntToString(i); 416 string url = "http://host" + base::IntToString(i) + "/low";
395 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); 417 lows.push_back(NewRequest(url.c_str(), net::LOWEST));
396 } 418 }
397 419
398 scheduler_.OnWillInsertBody(kChildId, kRouteId); 420 scheduler_.OnWillInsertBody(kChildId, kRouteId);
399 EXPECT_FALSE(request->started()); 421 EXPECT_FALSE(request->started());
400 EXPECT_TRUE(idle->started()); 422 EXPECT_TRUE(idle->started());
401 } 423 }
402 424
403 TEST_F(ResourceSchedulerTest, ReprioritizedRequestGoesToBackOfQueue) { 425 TEST_F(ResourceSchedulerTest, ReprioritizedRequestGoesToBackOfQueue) {
404 // Dummies to enforce scheduling. 426 // Dummies to enforce scheduling.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 scoped_ptr<TestRequest> low(NewRequest("http://host/high", net::LOWEST)); 458 scoped_ptr<TestRequest> low(NewRequest("http://host/high", net::LOWEST));
437 459
438 scoped_ptr<TestRequest> request( 460 scoped_ptr<TestRequest> request(
439 NewRequest("chrome-extension://req", net::LOWEST)); 461 NewRequest("chrome-extension://req", net::LOWEST));
440 EXPECT_TRUE(request->started()); 462 EXPECT_TRUE(request->started());
441 } 463 }
442 464
443 } // unnamed namespace 465 } // unnamed namespace
444 466
445 } // namespace content 467 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698