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

Side by Side Diff: net/http/http_cache_unittest.cc

Issue 17217: When there are multiple requests for the same resource, it is possible that c... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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/http/http_cache.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include "base/hash_tables.h" 7 #include "base/hash_tables.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 525 EXPECT_EQ(1, cache.network_layer()->transaction_count());
526 EXPECT_EQ(0, cache.disk_cache()->open_count()); 526 EXPECT_EQ(0, cache.disk_cache()->open_count());
527 EXPECT_EQ(1, cache.disk_cache()->create_count()); 527 EXPECT_EQ(1, cache.disk_cache()->create_count());
528 528
529 for (int i = 0; i < kNumTransactions; ++i) { 529 for (int i = 0; i < kNumTransactions; ++i) {
530 Context* c = context_list[i]; 530 Context* c = context_list[i];
531 delete c; 531 delete c;
532 } 532 }
533 } 533 }
534 534
535 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4769.
536 // If cancelling a request is racing with another request for the same resource
537 // finishing, we have to make sure that we remove both transactions from the
538 // entry.
539 TEST(HttpCache, SimpleGET_RacingReaders) {
540 MockHttpCache cache;
541
542 MockHttpRequest request(kSimpleGET_Transaction);
543 MockHttpRequest reader_request(kSimpleGET_Transaction);
544 reader_request.load_flags = net::LOAD_ONLY_FROM_CACHE;
545
546 std::vector<Context*> context_list;
547 const int kNumTransactions = 5;
548
549 for (int i = 0; i < kNumTransactions; ++i) {
550 context_list.push_back(
551 new Context(cache.http_cache()->CreateTransaction()));
552
553 Context* c = context_list[i];
554 MockHttpRequest* this_request = &request;
555 if (i == 1 || i == 2)
556 this_request = &reader_request;
557
558 int rv = c->trans->Start(this_request, &c->callback);
559 if (rv != net::ERR_IO_PENDING)
560 c->result = rv;
561 }
562
563 // The first request should be a writer at this point, and the subsequent
564 // requests should be pending.
565
566 EXPECT_EQ(1, cache.network_layer()->transaction_count());
567 EXPECT_EQ(0, cache.disk_cache()->open_count());
568 EXPECT_EQ(1, cache.disk_cache()->create_count());
569
570 Context* c = context_list[0];
571 ASSERT_EQ(net::ERR_IO_PENDING, c->result);
572 c->result = c->callback.WaitForResult();
573 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
574
575 // Now we have 2 active readers and two queued transactions.
576
577 c = context_list[1];
578 ASSERT_EQ(net::ERR_IO_PENDING, c->result);
579 c->result = c->callback.WaitForResult();
580 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
581
582 // At this point we have one reader, two pending transactions and a task on
583 // the queue to move to the next transaction. Now we cancel the request that
584 // is the current reader, and expect the queued task to be able to start the
585 // next request.
586
587 c = context_list[2];
588 c->trans.reset();
589
590 for (int i = 3; i < kNumTransactions; ++i) {
591 Context* c = context_list[i];
592 if (c->result == net::ERR_IO_PENDING)
593 c->result = c->callback.WaitForResult();
594 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
595 }
596
597 // We should not have had to re-open the disk entry.
598
599 EXPECT_EQ(1, cache.network_layer()->transaction_count());
600 EXPECT_EQ(0, cache.disk_cache()->open_count());
601 EXPECT_EQ(1, cache.disk_cache()->create_count());
602
603 for (int i = 0; i < kNumTransactions; ++i) {
604 Context* c = context_list[i];
605 delete c;
606 }
607 }
608
535 TEST(HttpCache, SimpleGET_ManyWriters_CancelFirst) { 609 TEST(HttpCache, SimpleGET_ManyWriters_CancelFirst) {
536 MockHttpCache cache; 610 MockHttpCache cache;
537 611
538 MockHttpRequest request(kSimpleGET_Transaction); 612 MockHttpRequest request(kSimpleGET_Transaction);
539 613
540 std::vector<Context*> context_list; 614 std::vector<Context*> context_list;
541 const int kNumTransactions = 2; 615 const int kNumTransactions = 2;
542 616
543 for (int i = 0; i < kNumTransactions; ++i) { 617 for (int i = 0; i < kNumTransactions; ++i) {
544 context_list.push_back( 618 context_list.push_back(
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 1081
1008 scoped_ptr<net::HttpTransaction> trans( 1082 scoped_ptr<net::HttpTransaction> trans(
1009 cache.http_cache()->CreateTransaction()); 1083 cache.http_cache()->CreateTransaction());
1010 ASSERT_TRUE(trans.get()); 1084 ASSERT_TRUE(trans.get());
1011 1085
1012 int rv = trans->Start(&request, &callback); 1086 int rv = trans->Start(&request, &callback);
1013 if (rv == net::ERR_IO_PENDING) 1087 if (rv == net::ERR_IO_PENDING)
1014 rv = callback.WaitForResult(); 1088 rv = callback.WaitForResult();
1015 ASSERT_EQ(net::ERR_CACHE_MISS, rv); 1089 ASSERT_EQ(net::ERR_CACHE_MISS, rv);
1016 } 1090 }
OLDNEW
« no previous file with comments | « net/http/http_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698