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

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

Issue 10832329: Update next_id when loading sync DB (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tests and fixes 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
« sync/syncable/directory.cc ('K') | « sync/syncable/directory.cc ('k') | 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 <string> 5 #include <string>
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 bool is_del); 513 bool is_del);
514 514
515 // When a directory is saved then loaded from disk, it will pass through 515 // When a directory is saved then loaded from disk, it will pass through
516 // DropDeletedEntries(). This will remove some entries from the directory. 516 // DropDeletedEntries(). This will remove some entries from the directory.
517 // This function is intended to simulate that process. 517 // This function is intended to simulate that process.
518 // 518 //
519 // WARNING: The directory will be deleted by this operation. You should 519 // WARNING: The directory will be deleted by this operation. You should
520 // not have any pointers to the directory (open transactions included) 520 // not have any pointers to the directory (open transactions included)
521 // when you call this. 521 // when you call this.
522 DirOpenResult SimulateSaveAndReloadDir(); 522 DirOpenResult SimulateSaveAndReloadDir();
523
524 // This function will close and re-open the directory without saving any
525 // pending changes. This is intended to simulate the recovery from a crash
526 // scenario. The same warnings for SimulateSaveAndReloadDir apply here.
527 DirOpenResult SimulateCrashAndReloadDir();
528
529 private:
530 // A helper function for Simulate{Save,Crash}AndReloadDir.
531 DirOpenResult ReloadDirImpl();
523 }; 532 };
524 533
525 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsMetahandlesToPurge) { 534 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsMetahandlesToPurge) {
526 const int metas_to_create = 50; 535 const int metas_to_create = 50;
527 MetahandleSet expected_purges; 536 MetahandleSet expected_purges;
528 MetahandleSet all_handles; 537 MetahandleSet all_handles;
529 { 538 {
530 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 539 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
531 for (int i = 0; i < metas_to_create; i++) { 540 for (int i = 0; i < metas_to_create; i++) {
532 MutableEntry e(&trans, CREATE, trans.root_id(), "foo"); 541 MutableEntry e(&trans, CREATE, trans.root_id(), "foo");
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 ChangeEntryIDAndUpdateChildren(&trans, &parent, id_factory.NewServerId()); 1263 ChangeEntryIDAndUpdateChildren(&trans, &parent, id_factory.NewServerId());
1255 parent.Put(IS_UNSYNCED, false); 1264 parent.Put(IS_UNSYNCED, false);
1256 parent.Put(BASE_VERSION, 1); 1265 parent.Put(BASE_VERSION, 1);
1257 parent.Put(SERVER_VERSION, 1); 1266 parent.Put(SERVER_VERSION, 1);
1258 } 1267 }
1259 1268
1260 // Final check for validity. 1269 // Final check for validity.
1261 EXPECT_EQ(OPENED, SimulateSaveAndReloadDir()); 1270 EXPECT_EQ(OPENED, SimulateSaveAndReloadDir());
1262 } 1271 }
1263 1272
1273 // Ask the directory to generate a unique ID. Close and re-open the database
1274 // without saving, then ask for another unique ID. Verify IDs are not reused.
1275 // This scenario simulates a crash within the first few seconds of operation.
1276 TEST_F(SyncableDirectoryTest, LocalIdReuseTest) {
1277 Id pre_crash_id = dir_->NextId();
1278 SimulateCrashAndReloadDir();
1279 Id post_crash_id = dir_->NextId();
1280 EXPECT_NE(pre_crash_id, post_crash_id);
1281 }
1282
1283 // Ask the directory to generate a unique ID. Save the directory. Close and
1284 // re-open the database without saving, then ask for another unique ID. Verify
1285 // IDs are not reused. This scenario simulates a steady-state crash.
1286 TEST_F(SyncableDirectoryTest, LocalIdReuseTestWithSave) {
1287 Id pre_crash_id = dir_->NextId();
1288 dir_->SaveChanges();
1289 SimulateCrashAndReloadDir();
1290 Id post_crash_id = dir_->NextId();
1291 EXPECT_NE(pre_crash_id, post_crash_id);
1292 }
1293
1264 // Ensure that the unsynced, is_del and server unkown entries that may have been 1294 // Ensure that the unsynced, is_del and server unkown entries that may have been
1265 // left in the database by old clients will be deleted when we open the old 1295 // left in the database by old clients will be deleted when we open the old
1266 // database. 1296 // database.
1267 TEST_F(SyncableDirectoryTest, OldClientLeftUnsyncedDeletedLocalItem) { 1297 TEST_F(SyncableDirectoryTest, OldClientLeftUnsyncedDeletedLocalItem) {
1268 // We must create an entry with the offending properties. This is done with 1298 // We must create an entry with the offending properties. This is done with
1269 // some abuse of the MutableEntry's API; it doesn't expect us to modify an 1299 // some abuse of the MutableEntry's API; it doesn't expect us to modify an
1270 // item after it is deleted. If this hack becomes impractical we will need to 1300 // item after it is deleted. If this hack becomes impractical we will need to
1271 // find a new way to simulate this scenario. 1301 // find a new way to simulate this scenario.
1272 1302
1273 TestIdFactory id_factory; 1303 TestIdFactory id_factory;
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 ASSERT_TRUE(name == e.Get(NON_UNIQUE_NAME)); 1744 ASSERT_TRUE(name == e.Get(NON_UNIQUE_NAME));
1715 ASSERT_TRUE(base_version == e.Get(BASE_VERSION)); 1745 ASSERT_TRUE(base_version == e.Get(BASE_VERSION));
1716 ASSERT_TRUE(server_version == e.Get(SERVER_VERSION)); 1746 ASSERT_TRUE(server_version == e.Get(SERVER_VERSION));
1717 ASSERT_TRUE(is_del == e.Get(IS_DEL)); 1747 ASSERT_TRUE(is_del == e.Get(IS_DEL));
1718 } 1748 }
1719 1749
1720 DirOpenResult SyncableDirectoryTest::SimulateSaveAndReloadDir() { 1750 DirOpenResult SyncableDirectoryTest::SimulateSaveAndReloadDir() {
1721 if (!dir_->SaveChanges()) 1751 if (!dir_->SaveChanges())
1722 return FAILED_IN_UNITTEST; 1752 return FAILED_IN_UNITTEST;
1723 1753
1754 return ReloadDirImpl();
1755 }
1756
1757 DirOpenResult SyncableDirectoryTest::SimulateCrashAndReloadDir() {
1758 return ReloadDirImpl();
1759 }
1760
1761 DirOpenResult SyncableDirectoryTest::ReloadDirImpl() {
1724 // Do some tricky things to preserve the backing store. 1762 // Do some tricky things to preserve the backing store.
1725 DirectoryBackingStore* saved_store = dir_->store_.release(); 1763 DirectoryBackingStore* saved_store = dir_->store_.release();
1726 1764
1727 // Close the current directory. 1765 // Close the current directory.
1728 dir_->Close(); 1766 dir_->Close();
1729 dir_.reset(); 1767 dir_.reset();
1730 1768
1731 dir_.reset(new Directory(&encryptor_, &handler_, NULL, saved_store)); 1769 dir_.reset(new Directory(&encryptor_, &handler_, NULL, saved_store));
1732 DirOpenResult result = dir_->OpenImpl(kName, &delegate_, 1770 DirOpenResult result = dir_->OpenImpl(kName, &delegate_,
1733 NullTransactionObserver()); 1771 NullTransactionObserver());
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1940 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1978 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true));
1941 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1979 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true));
1942 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); 1980 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false));
1943 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); 1981 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false));
1944 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); 1982 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true));
1945 } 1983 }
1946 1984
1947 } // namespace 1985 } // namespace
1948 } // namespace syncable 1986 } // namespace syncable
1949 } // namespace syncer 1987 } // namespace syncer
OLDNEW
« sync/syncable/directory.cc ('K') | « sync/syncable/directory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698