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

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: Feedback addressed. 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(3, cache.disk_cache()->create_count());
2017 } 2011 }
2018 2012
2019 // Tests when a writer is destroyed mid-read and entry is marked as truncated, 2013 // Tests when a writer is destroyed mid-read and entry is marked as truncated,
2020 // it should lead to restarting the dependent transactions. 2014 // it should lead to restarting the dependent transactions.
2021 TEST(HttpCache, SimpleGET_ParallelValidationCancelWriterTruncateEntry) { 2015 TEST(HttpCache, SimpleGET_ParallelValidationCancelWriterTruncateEntry) {
2022 MockHttpCache cache; 2016 MockHttpCache cache;
2023 2017
2024 ScopedMockTransaction transaction(kSimpleGET_Transaction); 2018 ScopedMockTransaction transaction(kSimpleGET_Transaction);
2025 transaction.response_headers = 2019 transaction.response_headers =
2026 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 2020 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 2129
2136 base::RunLoop().RunUntilIdle(); 2130 base::RunLoop().RunUntilIdle();
2137 2131
2138 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url)); 2132 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
2139 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url)); 2133 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
2140 2134
2141 // Resume network start for the transaction the second time. 2135 // Resume network start for the transaction the second time.
2142 c->trans->ResumeNetworkStart(); 2136 c->trans->ResumeNetworkStart();
2143 base::RunLoop().RunUntilIdle(); 2137 base::RunLoop().RunUntilIdle();
2144 2138
2145 // Headers transaction would have doomed the new entry created.
2146 EXPECT_TRUE(
2147 cache.disk_cache()->IsDiskEntryDoomed(kSimpleGET_Transaction.url));
2148
2149 // Complete the rest of the transactions. 2139 // Complete the rest of the transactions.
2150 for (auto& context : context_list) { 2140 for (auto& context : context_list) {
2151 if (!context) 2141 if (!context)
2152 continue; 2142 continue;
2153 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction); 2143 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction);
2154 } 2144 }
2155 2145
2156 EXPECT_EQ(4, cache.network_layer()->transaction_count()); 2146 EXPECT_EQ(4, cache.network_layer()->transaction_count());
2157 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2147 EXPECT_EQ(0, cache.disk_cache()->open_count());
2158 EXPECT_EQ(2, cache.disk_cache()->create_count()); 2148 EXPECT_EQ(3, cache.disk_cache()->create_count());
2159 } 2149 }
2160 2150
2161 // Tests that a transaction is currently in headers phase and is destroyed 2151 // Tests that a transaction is currently in headers phase and is destroyed
2162 // leading to destroying the entry. 2152 // leading to destroying the entry.
2163 TEST(HttpCache, SimpleGET_ParallelValidationCancelHeaders) { 2153 TEST(HttpCache, SimpleGET_ParallelValidationCancelHeaders) {
2164 MockHttpCache cache; 2154 MockHttpCache cache;
2165 2155
2166 MockHttpRequest request(kSimpleGET_Transaction); 2156 MockHttpRequest request(kSimpleGET_Transaction);
2167 2157
2168 const int kNumTransactions = 2; 2158 const int kNumTransactions = 2;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
2442 2432
2443 // Allow all requests to move from the Create queue to the active entry. 2433 // Allow all requests to move from the Create queue to the active entry.
2444 base::RunLoop().RunUntilIdle(); 2434 base::RunLoop().RunUntilIdle();
2445 2435
2446 // The first request should be a writer at this point, and the subsequent 2436 // The first request should be a writer at this point, and the subsequent
2447 // requests should have completed validation. Since the validation does not 2437 // requests should have completed validation. Since the validation does not
2448 // result in a match, a new entry would be created. 2438 // result in a match, a new entry would be created.
2449 2439
2450 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 2440 EXPECT_EQ(3, cache.network_layer()->transaction_count());
2451 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2441 EXPECT_EQ(0, cache.disk_cache()->open_count());
2452 EXPECT_EQ(2, cache.disk_cache()->create_count()); 2442 EXPECT_EQ(3, cache.disk_cache()->create_count());
2453 2443
2454 // Now, make sure that the second request asks for the entry not to be stored. 2444 // Now, make sure that the second request asks for the entry not to be stored.
2455 request_handler.set_no_store(true); 2445 request_handler.set_no_store(true);
2456 2446
2457 for (int i = 0; i < kNumTransactions; ++i) { 2447 for (int i = 0; i < kNumTransactions; ++i) {
2458 Context* c = context_list[i].get(); 2448 Context* c = context_list[i].get();
2459 if (c->result == ERR_IO_PENDING) 2449 if (c->result == ERR_IO_PENDING)
2460 c->result = c->callback.WaitForResult(); 2450 c->result = c->callback.WaitForResult();
2461 ReadAndVerifyTransaction(c->trans.get(), kFastNoStoreGET_Transaction); 2451 ReadAndVerifyTransaction(c->trans.get(), kFastNoStoreGET_Transaction);
2462 context_list[i].reset(); 2452 context_list[i].reset();
2463 } 2453 }
2464 2454
2465 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 2455 EXPECT_EQ(3, cache.network_layer()->transaction_count());
2466 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2456 EXPECT_EQ(0, cache.disk_cache()->open_count());
2467 EXPECT_EQ(2, cache.disk_cache()->create_count()); 2457 EXPECT_EQ(3, cache.disk_cache()->create_count());
2468 2458
2469 RemoveMockTransaction(&kFastNoStoreGET_Transaction); 2459 RemoveMockTransaction(&kFastNoStoreGET_Transaction);
2470 } 2460 }
2471 2461
2472 TEST(HttpCache, SimpleGET_ManyWriters_CancelFirst) { 2462 TEST(HttpCache, SimpleGET_ManyWriters_CancelFirst) {
2473 MockHttpCache cache; 2463 MockHttpCache cache;
2474 2464
2475 MockHttpRequest request(kSimpleGET_Transaction); 2465 MockHttpRequest request(kSimpleGET_Transaction);
2476 2466
2477 std::vector<std::unique_ptr<Context>> context_list; 2467 std::vector<std::unique_ptr<Context>> context_list;
(...skipping 6594 matching lines...) Expand 10 before | Expand all | Expand 10 after
9072 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); 9062 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs));
9073 base::DictionaryValue* size_attrs; 9063 base::DictionaryValue* size_attrs;
9074 ASSERT_TRUE(attrs->GetDictionary( 9064 ASSERT_TRUE(attrs->GetDictionary(
9075 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs)); 9065 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs));
9076 std::string size; 9066 std::string size;
9077 ASSERT_TRUE(size_attrs->GetString("value", &size)); 9067 ASSERT_TRUE(size_attrs->GetString("value", &size));
9078 int actual_size = 0; 9068 int actual_size = 0;
9079 ASSERT_TRUE(base::HexStringToInt(size, &actual_size)); 9069 ASSERT_TRUE(base::HexStringToInt(size, &actual_size));
9080 ASSERT_LT(0, actual_size); 9070 ASSERT_LT(0, actual_size);
9081 } 9071 }
9082 9072
jkarlin 2017/06/16 18:28:01 Please add a test in which there are 5 transaction
shivanisha 2017/06/27 15:31:14 test added.
9083 } // namespace net 9073 } // namespace net
OLDNEW
« net/http/http_cache_transaction.cc ('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