Fix broken test in 31b02d.

Summary:
CorruptionTest for backupable_db_test did not call
GarbageCollect() after deleting a corrupt backup,
which sometimes lead to test failures as the newly created backup
would reuse the same backup ID and files and fail the consistency
check.

Moved around some of the test logic to ensure that GarbageCollect()
is called at the right time.

Test Plan:
Run backupable_db_test eight times and make sure
it passes repeatedly. Also run make check to make sure other
tests don't fail.

Reviewers: igor

Reviewed By: igor

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D28863
This commit is contained in:
Hasnain Lakhani 2014-11-13 14:46:30 -08:00
parent 772bc97f13
commit 373c665edf

View File

@ -636,16 +636,6 @@ TEST(BackupableDBTest, CorruptionsTest) {
ASSERT_TRUE(file_manager_->FileExists(backupdir_ + "/meta/2"));
s = restore_db_->RestoreDBFromBackup(2, dbname_, dbname_);
ASSERT_TRUE(!s.ok());
ASSERT_OK(restore_db_->DeleteBackup(2));
CloseRestoreDB();
AssertBackupConsistency(0, 0, keys_iteration * 1, keys_iteration * 5);
// new backup should be 2!
OpenBackupableDB();
FillDB(db_.get(), keys_iteration * 1, keys_iteration * 2);
ASSERT_OK(db_->CreateNewBackup(!!(rnd.Next() % 2)));
CloseBackupableDB();
AssertBackupConsistency(2, 0, keys_iteration * 2, keys_iteration * 5);
// make sure that no corrupt backups have actually been deleted!
ASSERT_TRUE(file_manager_->FileExists(backupdir_ + "/meta/1"));
@ -660,18 +650,29 @@ TEST(BackupableDBTest, CorruptionsTest) {
ASSERT_TRUE(file_manager_->FileExists(backupdir_ + "/private/5"));
// delete the corrupt backups and then make sure they're actually deleted
OpenBackupableDB();
ASSERT_OK(db_->DeleteBackup(5));
ASSERT_OK(db_->DeleteBackup(4));
ASSERT_OK(db_->DeleteBackup(3));
(void) db_->GarbageCollect();
ASSERT_OK(restore_db_->DeleteBackup(5));
ASSERT_OK(restore_db_->DeleteBackup(4));
ASSERT_OK(restore_db_->DeleteBackup(3));
ASSERT_OK(restore_db_->DeleteBackup(2));
(void) restore_db_->GarbageCollect();
ASSERT_TRUE(file_manager_->FileExists(backupdir_ + "/meta/5") == false);
ASSERT_TRUE(file_manager_->FileExists(backupdir_ + "/private/5") == false);
ASSERT_TRUE(file_manager_->FileExists(backupdir_ + "/meta/4") == false);
ASSERT_TRUE(file_manager_->FileExists(backupdir_ + "/private/4") == false);
ASSERT_TRUE(file_manager_->FileExists(backupdir_ + "/meta/3") == false);
ASSERT_TRUE(file_manager_->FileExists(backupdir_ + "/private/3") == false);
ASSERT_TRUE(file_manager_->FileExists(backupdir_ + "/meta/2") == false);
ASSERT_TRUE(file_manager_->FileExists(backupdir_ + "/private/2") == false);
CloseRestoreDB();
AssertBackupConsistency(0, 0, keys_iteration * 1, keys_iteration * 5);
// new backup should be 2!
OpenBackupableDB();
FillDB(db_.get(), keys_iteration * 1, keys_iteration * 2);
ASSERT_OK(db_->CreateNewBackup(!!(rnd.Next() % 2)));
CloseBackupableDB();
AssertBackupConsistency(2, 0, keys_iteration * 2, keys_iteration * 5);
}
// open DB, write, close DB, backup, restore, repeat