Index: sync/syncable/syncable_unittest.cc |
diff --git a/sync/syncable/syncable_unittest.cc b/sync/syncable/syncable_unittest.cc |
index cf34a94ec93eef46ec419698ce3602683cbbbd4e..02af9aec6e43453ae303d6659b4c99a3c57fdf8c 100644 |
--- a/sync/syncable/syncable_unittest.cc |
+++ b/sync/syncable/syncable_unittest.cc |
@@ -520,6 +520,15 @@ class SyncableDirectoryTest : public testing::Test { |
// not have any pointers to the directory (open transactions included) |
// when you call this. |
DirOpenResult SimulateSaveAndReloadDir(); |
+ |
+ // This function will close and re-open the directory without saving any |
+ // pending changes. This is intended to simulate the recovery from a crash |
+ // scenario. The same warnings for SimulateSaveAndReloadDir apply here. |
+ DirOpenResult SimulateCrashAndReloadDir(); |
+ |
+ private: |
+ // A helper function for Simulate{Save,Crash}AndReloadDir. |
+ DirOpenResult ReloadDirImpl(); |
}; |
TEST_F(SyncableDirectoryTest, TakeSnapshotGetsMetahandlesToPurge) { |
@@ -1261,6 +1270,27 @@ TEST_F(SyncableDirectoryTest, |
EXPECT_EQ(OPENED, SimulateSaveAndReloadDir()); |
} |
+// Ask the directory to generate a unique ID. Close and re-open the database |
+// without saving, then ask for another unique ID. Verify IDs are not reused. |
+// This scenario simulates a crash within the first few seconds of operation. |
+TEST_F(SyncableDirectoryTest, LocalIdReuseTest) { |
+ Id pre_crash_id = dir_->NextId(); |
+ SimulateCrashAndReloadDir(); |
+ Id post_crash_id = dir_->NextId(); |
+ EXPECT_NE(pre_crash_id, post_crash_id); |
+} |
+ |
+// Ask the directory to generate a unique ID. Save the directory. Close and |
+// re-open the database without saving, then ask for another unique ID. Verify |
+// IDs are not reused. This scenario simulates a steady-state crash. |
+TEST_F(SyncableDirectoryTest, LocalIdReuseTestWithSave) { |
+ Id pre_crash_id = dir_->NextId(); |
+ dir_->SaveChanges(); |
+ SimulateCrashAndReloadDir(); |
+ Id post_crash_id = dir_->NextId(); |
+ EXPECT_NE(pre_crash_id, post_crash_id); |
+} |
+ |
// Ensure that the unsynced, is_del and server unkown entries that may have been |
// left in the database by old clients will be deleted when we open the old |
// database. |
@@ -1721,6 +1751,14 @@ DirOpenResult SyncableDirectoryTest::SimulateSaveAndReloadDir() { |
if (!dir_->SaveChanges()) |
return FAILED_IN_UNITTEST; |
+ return ReloadDirImpl(); |
+} |
+ |
+DirOpenResult SyncableDirectoryTest::SimulateCrashAndReloadDir() { |
+ return ReloadDirImpl(); |
+} |
+ |
+DirOpenResult SyncableDirectoryTest::ReloadDirImpl() { |
// Do some tricky things to preserve the backing store. |
DirectoryBackingStore* saved_store = dir_->store_.release(); |