From 373c665edf5dead0778c3ee5b2d304778183a317 Mon Sep 17 00:00:00 2001 From: Hasnain Lakhani Date: Thu, 13 Nov 2014 14:46:30 -0800 Subject: [PATCH] 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 --- utilities/backupable/backupable_db_test.cc | 31 +++++++++++----------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/utilities/backupable/backupable_db_test.cc b/utilities/backupable/backupable_db_test.cc index 7ca5acad8..46fc7cb6f 100644 --- a/utilities/backupable/backupable_db_test.cc +++ b/utilities/backupable/backupable_db_test.cc @@ -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