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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | 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) 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 3868 matching lines...) Expand 10 before | Expand all | Expand 10 after
3879 OpenEntry(*(keys_to_match.begin()), &entry_opened_middle)); 3879 OpenEntry(*(keys_to_match.begin()), &entry_opened_middle));
3880 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count)); 3880 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count));
3881 iter.reset(); 3881 iter.reset();
3882 entry_opened_before->Close(); 3882 entry_opened_before->Close();
3883 entry_opened_middle->Close(); 3883 entry_opened_middle->Close();
3884 3884
3885 EXPECT_EQ(key_pool.size(), count); 3885 EXPECT_EQ(key_pool.size(), count);
3886 EXPECT_TRUE(keys_to_match.empty()); 3886 EXPECT_TRUE(keys_to_match.empty());
3887 } 3887 }
3888 3888
3889 TEST_F(DiskCacheBackendTest, SimpleCacheIndexRecovery) {
3890 // Make sure we can recover set of entries when the index was removed.
3891 SetSimpleCacheMode();
3892 InitCache();
3893 std::set<std::string> key_pool;
3894 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool));
3895
3896 cache_.reset();
3897
3898 // Give it a chance to write out the index, so we can delete it (rather
3899 // than have it write it after we delete it).
3900 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
3901 base::RunLoop().RunUntilIdle();
3902
3903 base::FilePath index_path =
3904 cache_path_.AppendASCII("index-dir").AppendASCII("the-real-index");
3905 ASSERT_TRUE(base::DeleteFile(index_path, false));
3906
3907 DisableFirstCleanup();
3908 InitCache();
3909 // A bit surprising, but it calls it "NEWCACHE" if there was no index,
3910 // even if it reconstructed non-zero things.
3911 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_NEWCACHE,
3912 simple_cache_impl_->index()->init_method());
3913
3914 // Check that enumeration returns all entries.
3915 std::set<std::string> keys_to_match(key_pool);
3916 std::unique_ptr<TestIterator> iter = CreateIterator();
3917 size_t count = 0;
3918 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count));
3919 iter.reset();
3920 EXPECT_EQ(key_pool.size(), count);
3921 EXPECT_TRUE(keys_to_match.empty());
3922 }
3923
3889 // Tests that the enumerations are not affected by dooming an entry in the 3924 // Tests that the enumerations are not affected by dooming an entry in the
3890 // middle. 3925 // middle.
3891 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) { 3926 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) {
3892 SetSimpleCacheMode(); 3927 SetSimpleCacheMode();
3893 InitCache(); 3928 InitCache();
3894 std::set<std::string> key_pool; 3929 std::set<std::string> key_pool;
3895 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); 3930 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool));
3896 3931
3897 // Check that enumeration returns all entries but the doomed one. 3932 // Check that enumeration returns all entries but the doomed one.
3898 std::set<std::string> keys_to_match(key_pool); 3933 std::set<std::string> keys_to_match(key_pool);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
4084 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); 4119 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
4085 base::RunLoop().RunUntilIdle(); 4120 base::RunLoop().RunUntilIdle();
4086 4121
4087 disk_cache::Entry* reopen_entry1; 4122 disk_cache::Entry* reopen_entry1;
4088 ASSERT_THAT(OpenEntry(key1, &reopen_entry1), IsOk()); 4123 ASSERT_THAT(OpenEntry(key1, &reopen_entry1), IsOk());
4089 4124
4090 // This shouldn't pick up entry2's write time incorrectly. 4125 // This shouldn't pick up entry2's write time incorrectly.
4091 EXPECT_LE(reopen_entry1->GetLastModified(), entry1_timestamp); 4126 EXPECT_LE(reopen_entry1->GetLastModified(), entry1_timestamp);
4092 reopen_entry1->Close(); 4127 reopen_entry1->Close();
4093 } 4128 }
OLDNEW
« 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