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

Side by Side Diff: sync/syncable/directory_backing_store_unittest.cc

Issue 10821121: sync: Attempt to recover from directory corruption (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 2065 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 TEST_F(DirectoryBackingStoreTest, ModelTypeIds) { 2076 TEST_F(DirectoryBackingStoreTest, ModelTypeIds) {
2077 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 2077 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
2078 std::string model_id = 2078 std::string model_id =
2079 TestDirectoryBackingStore::ModelTypeEnumToModelId(ModelTypeFromInt(i)); 2079 TestDirectoryBackingStore::ModelTypeEnumToModelId(ModelTypeFromInt(i));
2080 EXPECT_EQ(i, 2080 EXPECT_EQ(i,
2081 TestDirectoryBackingStore::ModelIdToModelTypeEnum(model_id.data(), 2081 TestDirectoryBackingStore::ModelIdToModelTypeEnum(model_id.data(),
2082 model_id.size())); 2082 model_id.size()));
2083 } 2083 }
2084 } 2084 }
2085 2085
2086 // TODO(109668): This had to be disabled because the latest API will 2086 // This is a whitebox test intended to exercise the code path where the on-disk
2087 // intentionally crash when a database is this badly corrupted. 2087 // directory load code decides to delete the current directory and start fresh.
2088 TEST_F(DirectoryBackingStoreTest, DISABLED_Corruption) { 2088 //
2089 // Unfortunately, there's no way to tell that this code path is actually
2090 // exercised by the test. If the directory failed to detect the corruption, the
2091 // result would look exactly the same from this level of abstraction.
2092 //
2093 // This is considered "minor" corruption because the database recreation is
2094 // expected to succeed. The alternative, where recreation does not succeed (ie.
2095 // due to read-only file system), is not tested here.
2096 TEST_F(DirectoryBackingStoreTest, MinorCorruption) {
2089 { 2097 {
2090 scoped_ptr<OnDiskDirectoryBackingStore> dbs( 2098 scoped_ptr<OnDiskDirectoryBackingStore> dbs(
2091 new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath())); 2099 new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath()));
2092 EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); 2100 EXPECT_EQ(OPENED, LoadAndIgnoreReturnedData(dbs.get()));
2093 } 2101 }
2094 std::string bad_data("BAD DATA"); 2102
2095 EXPECT_TRUE(file_util::WriteFile(GetDatabasePath(), bad_data.data(), 2103 // Corrupt the root node.
2096 bad_data.size())); 2104 {
2105 sql::Connection connection;
2106 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2107 ASSERT_TRUE(connection.Execute(
2108 "UPDATE metas SET parent_id='bogus' WHERE id = 'r';"));
2109 }
2110
2097 { 2111 {
2098 scoped_ptr<OnDiskDirectoryBackingStore> dbs( 2112 scoped_ptr<OnDiskDirectoryBackingStore> dbs(
2099 new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath())); 2113 new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath()));
2114 dbs->AllowFailureForTest();
2100 2115
2101 EXPECT_FALSE(LoadAndIgnoreReturnedData(dbs.get())); 2116 EXPECT_EQ(OPENED, LoadAndIgnoreReturnedData(dbs.get()));
2102 } 2117 }
2103 } 2118 }
2104 2119
2105 TEST_F(DirectoryBackingStoreTest, DeleteEntries) { 2120 TEST_F(DirectoryBackingStoreTest, DeleteEntries) {
2106 sql::Connection connection; 2121 sql::Connection connection;
2107 ASSERT_TRUE(connection.OpenInMemory()); 2122 ASSERT_TRUE(connection.OpenInMemory());
2108 2123
2109 SetUpCurrentDatabaseAndCheckVersion(&connection); 2124 SetUpCurrentDatabaseAndCheckVersion(&connection);
2110 scoped_ptr<TestDirectoryBackingStore> dbs( 2125 scoped_ptr<TestDirectoryBackingStore> dbs(
2111 new TestDirectoryBackingStore(GetUsername(), &connection)); 2126 new TestDirectoryBackingStore(GetUsername(), &connection));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2153 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); 2168 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID();
2154 EXPECT_EQ(24U, guid1.size()); 2169 EXPECT_EQ(24U, guid1.size());
2155 EXPECT_EQ(24U, guid2.size()); 2170 EXPECT_EQ(24U, guid2.size());
2156 // In theory this test can fail, but it won't before the universe 2171 // In theory this test can fail, but it won't before the universe
2157 // dies of heat death. 2172 // dies of heat death.
2158 EXPECT_NE(guid1, guid2); 2173 EXPECT_NE(guid1, guid2);
2159 } 2174 }
2160 2175
2161 } // namespace syncable 2176 } // namespace syncable
2162 } // namespace syncer 2177 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698