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 0cc723fc7ce1e0958bb48f9eb5d5443623dc8dd4..435533c969d409ee3e30468f6667ade1fcb335ab 100644 |
--- a/sync/syncable/directory_backing_store_unittest.cc |
+++ b/sync/syncable/directory_backing_store_unittest.cc |
@@ -7,6 +7,8 @@ |
#include <string> |
#include "base/files/file_path.h" |
+#include "base/files/file_util.h" |
+#include "base/files/scoped_file.h" |
#include "base/files/scoped_temp_dir.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/message_loop/message_loop.h" |
@@ -25,7 +27,6 @@ |
#include "sync/syncable/directory_backing_store.h" |
#include "sync/syncable/on_disk_directory_backing_store.h" |
#include "sync/syncable/syncable-inl.h" |
-#include "sync/test/directory_backing_store_corruption_testing.h" |
#include "sync/test/test_directory_backing_store.h" |
#include "sync/util/time.h" |
#include "testing/gtest/include/gtest/gtest-param-test.h" |
@@ -4094,6 +4095,7 @@ |
bool was_called = false; |
const base::Closure handler = |
base::Bind(&CatastrophicErrorHandler, &was_called); |
+ |
// Create a DB with many entries. |
scoped_ptr<OnDiskDirectoryBackingStoreForTest> dbs( |
new OnDiskDirectoryBackingStoreForTest(GetUsername(), GetDatabasePath())); |
@@ -4102,19 +4104,32 @@ |
ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); |
ASSERT_FALSE(dbs->DidFailFirstOpenAttempt()); |
Directory::SaveChangesSnapshot snapshot; |
- for (int i = 0; i < corruption_testing::kNumEntriesRequiredForCorruption; |
- ++i) { |
+ const int num_entries = 4000; |
+ for (int i = 0; i < num_entries; ++i) { |
snapshot.dirty_metas.insert(CreateEntry(i).release()); |
} |
ASSERT_TRUE(dbs->SaveChanges(snapshot)); |
- // Corrupt it. |
- ASSERT_TRUE(corruption_testing::CorruptDatabase(GetDatabasePath())); |
+ |
+ // Corrupt the DB by write a bunch of zeros at the beginning. |
+ { |
+ // Because the file is already open for writing (see dbs above), it's |
+ // important that we open it in a sharing compatible way for platforms that |
+ // have the concept of shared/exclusive file access (e.g. Windows). |
+ base::ScopedFILE db_file(base::OpenFile(GetDatabasePath(), "wb")); |
+ ASSERT_TRUE(db_file.get()); |
+ const std::string zeros(4096, '\0'); |
+ ASSERT_EQ(1U, fwrite(zeros.data(), zeros.size(), 1, db_file.get())); |
+ } |
+ |
// Attempt to save all those entries again. See that it fails (because of the |
// corruption). |
// |
- // If this test fails because SaveChanges returned true, it may mean you need |
- // to increase the number of entries written to the DB. See also |
- // |kNumEntriesRequiredForCorruption|. |
+ // If this test fails because SaveChanges returned true, it may mean that you |
+ // need to increase the number of entries written to the DB. Try increasing |
+ // the value of num_entries above. The value needs to be large enough to force |
+ // the underlying DB to be read from disk before writing. The value *may* |
+ // depend on the underlying DB page size as well as the DB's cache_size |
+ // PRAGMA. |
ASSERT_FALSE(dbs->SaveChanges(snapshot)); |
// At this point the handler has been posted but not executed. |
ASSERT_FALSE(was_called); |