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

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

Issue 2774603003: Doom and create new entry when validation is not a match (Closed)
Patch Set: Rebased with parent branch Created 3 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
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/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 1686 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 } 1697 }
1698 1698
1699 // Allow all requests to move from the Create queue to the active entry. 1699 // Allow all requests to move from the Create queue to the active entry.
1700 base::RunLoop().RunUntilIdle(); 1700 base::RunLoop().RunUntilIdle();
1701 1701
1702 // The first request should be a writer at this point, and the subsequent 1702 // The first request should be a writer at this point, and the subsequent
1703 // requests should have passed the validation phase and created their own 1703 // requests should have passed the validation phase and created their own
1704 // entries since none of them matched the headers of the earlier one. 1704 // entries since none of them matched the headers of the earlier one.
1705 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url)); 1705 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1706 1706
1707 // Note that there are only 3 entries created and not 5 since every other
1708 // transaction would have gone to the network.
1709 EXPECT_EQ(5, cache.network_layer()->transaction_count()); 1707 EXPECT_EQ(5, cache.network_layer()->transaction_count());
1710 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1708 EXPECT_EQ(0, cache.disk_cache()->open_count());
1711 EXPECT_EQ(3, cache.disk_cache()->create_count()); 1709 EXPECT_EQ(5, cache.disk_cache()->create_count());
1712 1710
1713 // All requests depend on the writer, and the writer is between Start and 1711 // All requests depend on the writer, and the writer is between Start and
1714 // Read, i.e. idle. 1712 // Read, i.e. idle.
1715 for (auto& context : context_list) { 1713 for (auto& context : context_list) {
1716 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState()); 1714 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState());
1717 } 1715 }
1718 1716
1719 for (auto& context : context_list) { 1717 for (auto& context : context_list) {
1720 if (context->result == ERR_IO_PENDING) 1718 if (context->result == ERR_IO_PENDING)
1721 context->result = context->callback.WaitForResult(); 1719 context->result = context->callback.WaitForResult();
1722 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); 1720 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction);
1723 } 1721 }
1724 1722
1725 EXPECT_EQ(5, cache.network_layer()->transaction_count()); 1723 EXPECT_EQ(5, cache.network_layer()->transaction_count());
1726 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1724 EXPECT_EQ(0, cache.disk_cache()->open_count());
1727 EXPECT_EQ(3, cache.disk_cache()->create_count()); 1725 EXPECT_EQ(5, cache.disk_cache()->create_count());
1728 } 1726 }
1729 1727
1730 // Tests that a GET followed by a DELETE results in DELETE immediately starting 1728 // Tests that a GET followed by a DELETE results in DELETE immediately starting
1731 // the headers phase and the entry is doomed. 1729 // the headers phase and the entry is doomed.
1732 TEST(HttpCache, SimpleGET_ParallelValidationDelete) { 1730 TEST(HttpCache, SimpleGET_ParallelValidationDelete) {
1733 MockHttpCache cache; 1731 MockHttpCache cache;
1734 1732
1735 MockHttpRequest request(kSimpleGET_Transaction); 1733 MockHttpRequest request(kSimpleGET_Transaction);
1736 request.load_flags |= LOAD_VALIDATE_CACHE; 1734 request.load_flags |= LOAD_VALIDATE_CACHE;
1737 1735
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1919 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url)); 1917 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1920 1918
1921 // Resume network start for headers_transaction. It will doom the entry as it 1919 // Resume network start for headers_transaction. It will doom the entry as it
1922 // will be a 200 and will go to network for the response body. 1920 // will be a 200 and will go to network for the response body.
1923 auto& context = context_list[3]; 1921 auto& context = context_list[3];
1924 context->trans->ResumeNetworkStart(); 1922 context->trans->ResumeNetworkStart();
1925 1923
1926 // The pending transactions will be added to a new entry. 1924 // The pending transactions will be added to a new entry.
1927 base::RunLoop().RunUntilIdle(); 1925 base::RunLoop().RunUntilIdle();
1928 1926
1929 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url)); 1927 EXPECT_EQ(2, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1930 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url)); 1928 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1931 1929
1932 // Complete the rest of the transactions. 1930 // Complete the rest of the transactions.
1933 for (int i = 2; i < kNumTransactions; ++i) { 1931 for (int i = 2; i < kNumTransactions; ++i) {
1934 auto& c = context_list[i]; 1932 auto& c = context_list[i];
1935 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 1933 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1936 } 1934 }
1937 1935
1938 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 1936 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1939 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1937 EXPECT_EQ(0, cache.disk_cache()->open_count());
1940 EXPECT_EQ(2, cache.disk_cache()->create_count()); 1938 EXPECT_EQ(2, cache.disk_cache()->create_count());
1941 } 1939 }
1942 1940
1943 // Tests that a transaction is in validated queue and writer is destroyed 1941 // Tests that a transaction is in validated queue and writer is destroyed
1944 // leading to restarting the validated transaction. 1942 // leading to restarting the validated transaction.
1945 TEST(HttpCache, SimpleGET_ParallelValidationCancelWriter) { 1943 TEST(HttpCache, SimpleGET_ParallelValidationCancelWriter) {
1946 MockHttpCache cache; 1944 MockHttpCache cache;
1947 1945
1948 MockHttpRequest request(kSimpleGET_Transaction); 1946 MockHttpRequest request(kSimpleGET_Transaction);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1993 1991
1994 base::RunLoop().RunUntilIdle(); 1992 base::RunLoop().RunUntilIdle();
1995 1993
1996 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url)); 1994 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1997 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url)); 1995 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1998 1996
1999 // Resume network start for the transaction the second time. 1997 // Resume network start for the transaction the second time.
2000 c->trans->ResumeNetworkStart(); 1998 c->trans->ResumeNetworkStart();
2001 base::RunLoop().RunUntilIdle(); 1999 base::RunLoop().RunUntilIdle();
2002 2000
2003 // Headers transaction would have doomed the new entry created.
2004 EXPECT_TRUE(
2005 cache.disk_cache()->IsDiskEntryDoomed(kSimpleGET_Transaction.url));
2006
2007 // Complete the rest of the transactions. 2001 // Complete the rest of the transactions.
2008 for (auto& context : context_list) { 2002 for (auto& context : context_list) {
2009 if (!context) 2003 if (!context)
2010 continue; 2004 continue;
2011 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); 2005 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction);
2012 } 2006 }
2013 2007
2014 EXPECT_EQ(4, cache.network_layer()->transaction_count()); 2008 EXPECT_EQ(4, cache.network_layer()->transaction_count());
2015 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2009 EXPECT_EQ(0, cache.disk_cache()->open_count());
2016 EXPECT_EQ(2, cache.disk_cache()->create_count()); 2010 EXPECT_EQ(2, cache.disk_cache()->create_count());
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2148 2142
2149 // Complete the rest of the transactions. 2143 // Complete the rest of the transactions.
2150 for (auto& context : context_list) { 2144 for (auto& context : context_list) {
2151 if (!context) 2145 if (!context)
2152 continue; 2146 continue;
2153 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); 2147 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction);
2154 } 2148 }
2155 2149
2156 EXPECT_EQ(4, cache.network_layer()->transaction_count()); 2150 EXPECT_EQ(4, cache.network_layer()->transaction_count());
2157 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2151 EXPECT_EQ(0, cache.disk_cache()->open_count());
2158 EXPECT_EQ(2, cache.disk_cache()->create_count()); 2152 EXPECT_EQ(3, cache.disk_cache()->create_count());
2159 } 2153 }
2160 2154
2161 // Tests that a transaction is currently in headers phase and is destroyed 2155 // Tests that a transaction is currently in headers phase and is destroyed
2162 // leading to destroying the entry. 2156 // leading to destroying the entry.
2163 TEST(HttpCache, SimpleGET_ParallelValidationCancelHeaders) { 2157 TEST(HttpCache, SimpleGET_ParallelValidationCancelHeaders) {
2164 MockHttpCache cache; 2158 MockHttpCache cache;
2165 2159
2166 MockHttpRequest request(kSimpleGET_Transaction); 2160 MockHttpRequest request(kSimpleGET_Transaction);
2167 2161
2168 const int kNumTransactions = 2; 2162 const int kNumTransactions = 2;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
2442 2436
2443 // Allow all requests to move from the Create queue to the active entry. 2437 // Allow all requests to move from the Create queue to the active entry.
2444 base::RunLoop().RunUntilIdle(); 2438 base::RunLoop().RunUntilIdle();
2445 2439
2446 // The first request should be a writer at this point, and the subsequent 2440 // The first request should be a writer at this point, and the subsequent
2447 // requests should have completed validation. Since the validation does not 2441 // requests should have completed validation. Since the validation does not
2448 // result in a match, a new entry would be created. 2442 // result in a match, a new entry would be created.
2449 2443
2450 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 2444 EXPECT_EQ(3, cache.network_layer()->transaction_count());
2451 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2445 EXPECT_EQ(0, cache.disk_cache()->open_count());
2452 EXPECT_EQ(2, cache.disk_cache()->create_count()); 2446 EXPECT_EQ(3, cache.disk_cache()->create_count());
2453 2447
2454 // Now, make sure that the second request asks for the entry not to be stored. 2448 // Now, make sure that the second request asks for the entry not to be stored.
2455 request_handler.set_no_store(true); 2449 request_handler.set_no_store(true);
2456 2450
2457 for (int i = 0; i < kNumTransactions; ++i) { 2451 for (int i = 0; i < kNumTransactions; ++i) {
2458 Context* c = context_list[i].get(); 2452 Context* c = context_list[i].get();
2459 if (c->result == ERR_IO_PENDING) 2453 if (c->result == ERR_IO_PENDING)
2460 c->result = c->callback.WaitForResult(); 2454 c->result = c->callback.WaitForResult();
2461 ReadAndVerifyTransaction(c->trans.get(), kFastNoStoreGET_Transaction); 2455 ReadAndVerifyTransaction(c->trans.get(), kFastNoStoreGET_Transaction);
2462 context_list[i].reset(); 2456 context_list[i].reset();
2463 } 2457 }
2464 2458
2465 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 2459 EXPECT_EQ(3, cache.network_layer()->transaction_count());
2466 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2460 EXPECT_EQ(0, cache.disk_cache()->open_count());
2467 EXPECT_EQ(2, cache.disk_cache()->create_count()); 2461 EXPECT_EQ(3, cache.disk_cache()->create_count());
2468 2462
2469 RemoveMockTransaction(&kFastNoStoreGET_Transaction); 2463 RemoveMockTransaction(&kFastNoStoreGET_Transaction);
2470 } 2464 }
2471 2465
2472 TEST(HttpCache, SimpleGET_ManyWriters_CancelFirst) { 2466 TEST(HttpCache, SimpleGET_ManyWriters_CancelFirst) {
2473 MockHttpCache cache; 2467 MockHttpCache cache;
2474 2468
2475 MockHttpRequest request(kSimpleGET_Transaction); 2469 MockHttpRequest request(kSimpleGET_Transaction);
2476 2470
2477 std::vector<std::unique_ptr<Context>> context_list; 2471 std::vector<std::unique_ptr<Context>> context_list;
(...skipping 6596 matching lines...) Expand 10 before | Expand all | Expand 10 after
9074 ASSERT_TRUE(attrs->GetDictionary( 9068 ASSERT_TRUE(attrs->GetDictionary(
9075 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs)); 9069 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs));
9076 std::string size; 9070 std::string size;
9077 ASSERT_TRUE(size_attrs->GetString("value", &size)); 9071 ASSERT_TRUE(size_attrs->GetString("value", &size));
9078 int actual_size = 0; 9072 int actual_size = 0;
9079 ASSERT_TRUE(base::HexStringToInt(size, &actual_size)); 9073 ASSERT_TRUE(base::HexStringToInt(size, &actual_size));
9080 ASSERT_LT(0, actual_size); 9074 ASSERT_LT(0, actual_size);
9081 } 9075 }
9082 9076
9083 } // namespace net 9077 } // namespace net
OLDNEW
« net/http/http_cache_transaction.h ('K') | « net/http/http_cache_transaction.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698