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

Unified 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: Fix other win compile warning 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/syncable/directory_backing_store.cc ('k') | sync/syncable/in_memory_directory_backing_store.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/syncable/directory_backing_store_unittest.cc
diff --git a/sync/syncable/directory_backing_store_unittest.cc b/sync/syncable/directory_backing_store_unittest.cc
index 25aca638a8453b5da43fa7591f240581aa093ded..4a35d288674f8fb9a4f13bc4ea8fee4506705a1c 100644
--- a/sync/syncable/directory_backing_store_unittest.cc
+++ b/sync/syncable/directory_backing_store_unittest.cc
@@ -2083,22 +2083,69 @@ TEST_F(DirectoryBackingStoreTest, ModelTypeIds) {
}
}
-// TODO(109668): This had to be disabled because the latest API will
-// intentionally crash when a database is this badly corrupted.
-TEST_F(DirectoryBackingStoreTest, DISABLED_Corruption) {
+namespace {
+
+class OnDiskDirectoryBackingStoreForTest : public OnDiskDirectoryBackingStore {
+ public:
+ OnDiskDirectoryBackingStoreForTest(const std::string& dir_name,
+ const FilePath& backing_filepath);
+ virtual ~OnDiskDirectoryBackingStoreForTest();
+ bool DidFailFirstOpenAttempt();
+
+ protected:
+ virtual void ReportFirstTryOpenFailure() OVERRIDE;
+
+ private:
+ bool first_open_failed_;
+};
+
+OnDiskDirectoryBackingStoreForTest::OnDiskDirectoryBackingStoreForTest(
+ const std::string& dir_name,
+ const FilePath& backing_filepath) :
+ OnDiskDirectoryBackingStore(dir_name, backing_filepath),
+ first_open_failed_(false) { }
+
+OnDiskDirectoryBackingStoreForTest::~OnDiskDirectoryBackingStoreForTest() { }
+
+void OnDiskDirectoryBackingStoreForTest::ReportFirstTryOpenFailure() {
+ // Do nothing, just like we would in release-mode. In debug mode, we DCHECK.
+ first_open_failed_ = true;
+}
+
+bool OnDiskDirectoryBackingStoreForTest::DidFailFirstOpenAttempt() {
+ return first_open_failed_;
+}
+
+} // namespace
+
+// This is a whitebox test intended to exercise the code path where the on-disk
+// directory load code decides to delete the current directory and start fresh.
+//
+// This is considered "minor" corruption because the database recreation is
+// expected to succeed. The alternative, where recreation does not succeed (ie.
+// due to read-only file system), is not tested here.
+TEST_F(DirectoryBackingStoreTest, MinorCorruption) {
{
scoped_ptr<OnDiskDirectoryBackingStore> dbs(
new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath()));
EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
}
- std::string bad_data("BAD DATA");
- EXPECT_TRUE(file_util::WriteFile(GetDatabasePath(), bad_data.data(),
- bad_data.size()));
+
+ // Corrupt the root node.
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+ ASSERT_TRUE(connection.Execute(
+ "UPDATE metas SET parent_id='bogus' WHERE id = 'r';"));
+ }
+
{
- scoped_ptr<OnDiskDirectoryBackingStore> dbs(
- new OnDiskDirectoryBackingStore(GetUsername(), GetDatabasePath()));
+ scoped_ptr<OnDiskDirectoryBackingStoreForTest> dbs(
+ new OnDiskDirectoryBackingStoreForTest(GetUsername(),
+ GetDatabasePath()));
- EXPECT_FALSE(LoadAndIgnoreReturnedData(dbs.get()));
+ EXPECT_TRUE(LoadAndIgnoreReturnedData(dbs.get()));
+ EXPECT_TRUE(dbs->DidFailFirstOpenAttempt());
}
}
« no previous file with comments | « sync/syncable/directory_backing_store.cc ('k') | sync/syncable/in_memory_directory_backing_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698