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

Unified Diff: net/disk_cache/backend_unittest.cc

Issue 2878523002: SimpleCache: Add a test that covers recovery from missing index. (Closed)
Patch Set: Fix race, so it actually exercises the restore path consistently. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/backend_unittest.cc
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index ca0e0ee8754e18804dd8b13695208b6bfa747f90..79fcdf728352016fa0e23bd7539f47ba9fba7ecc 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -3886,6 +3886,41 @@ TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationBasics) {
EXPECT_TRUE(keys_to_match.empty());
}
+TEST_F(DiskCacheBackendTest, SimpleCacheIndexRecovery) {
+ // Make sure we can recover set of entries when the index was removed.
+ SetSimpleCacheMode();
+ InitCache();
+ std::set<std::string> key_pool;
+ ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool));
+
+ cache_.reset();
+
+ // Give it a chance to write out the index, so we can delete it (rather
+ // than have it write it after we delete it).
+ disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
+ base::RunLoop().RunUntilIdle();
+
+ base::FilePath index_path =
+ cache_path_.AppendASCII("index-dir").AppendASCII("the-real-index");
+ ASSERT_TRUE(base::DeleteFile(index_path, false));
+
+ DisableFirstCleanup();
+ InitCache();
+ // A bit surprising, but it calls it "NEWCACHE" if there was no index,
+ // even if it reconstructed non-zero things.
+ EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_NEWCACHE,
+ simple_cache_impl_->index()->init_method());
+
+ // Check that enumeration returns all entries.
+ std::set<std::string> keys_to_match(key_pool);
+ std::unique_ptr<TestIterator> iter = CreateIterator();
+ size_t count = 0;
+ ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count));
+ iter.reset();
+ EXPECT_EQ(key_pool.size(), count);
+ EXPECT_TRUE(keys_to_match.empty());
+}
+
// Tests that the enumerations are not affected by dooming an entry in the
// middle.
TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698