diff --git a/utilities/backupable/backupable_db_test.cc b/utilities/backupable/backupable_db_test.cc index f33ca73a0..677bcba56 100644 --- a/utilities/backupable/backupable_db_test.cc +++ b/utilities/backupable/backupable_db_test.cc @@ -594,6 +594,17 @@ class BackupableDBTest : public testing::Test { return db; } + void CloseAndReopenDB() { + // Close DB + db_.reset(); + + // Open DB + test_db_env_->SetLimitWrittenFiles(1000000); + DB* db; + ASSERT_OK(DB::Open(options_, dbname_, &db)); + db_.reset(db); + } + void OpenDBAndBackupEngine(bool destroy_old_data = false, bool dummy = false, ShareOption shared_option = kShareNoChecksum) { // reset all the defaults @@ -1186,12 +1197,14 @@ TEST_F(BackupableDBTest, TableFileCorruptedBeforeBackup) { kNoShare); FillDB(db_.get(), 0, keys_iteration); ASSERT_OK(db_->Flush(FlushOptions())); + CloseAndReopenDB(); // corrupt a random table file in the DB directory ASSERT_OK(CorruptRandomTableFileInDB()); // file_checksum_gen_factory is null, and thus table checksum is not // verified for creating a new backup; no correction is detected ASSERT_OK(backup_engine_->CreateNewBackup(db_.get())); CloseDBAndBackupEngine(); + // delete old files in db ASSERT_OK(DestroyDB(dbname_, options_)); @@ -1201,12 +1214,12 @@ TEST_F(BackupableDBTest, TableFileCorruptedBeforeBackup) { kNoShare); FillDB(db_.get(), 0, keys_iteration); ASSERT_OK(db_->Flush(FlushOptions())); + CloseAndReopenDB(); // corrupt a random table file in the DB directory ASSERT_OK(CorruptRandomTableFileInDB()); // table file checksum is enabled so we should be able to detect any // corruption ASSERT_NOK(backup_engine_->CreateNewBackup(db_.get())); - CloseDBAndBackupEngine(); } @@ -1219,11 +1232,13 @@ TEST_P(BackupableDBTestWithParam, TableFileCorruptedBeforeBackup) { OpenDBAndBackupEngine(true /* destroy_old_data */); FillDB(db_.get(), 0, keys_iteration); ASSERT_OK(db_->Flush(FlushOptions())); + CloseAndReopenDB(); // corrupt a random table file in the DB directory ASSERT_OK(CorruptRandomTableFileInDB()); // cannot detect corruption since DB manifest has no table checksums ASSERT_OK(backup_engine_->CreateNewBackup(db_.get())); CloseDBAndBackupEngine(); + // delete old files in db ASSERT_OK(DestroyDB(dbname_, options_)); @@ -1232,11 +1247,11 @@ TEST_P(BackupableDBTestWithParam, TableFileCorruptedBeforeBackup) { OpenDBAndBackupEngine(true /* destroy_old_data */); FillDB(db_.get(), 0, keys_iteration); ASSERT_OK(db_->Flush(FlushOptions())); + CloseAndReopenDB(); // corrupt a random table file in the DB directory ASSERT_OK(CorruptRandomTableFileInDB()); // corruption is detected ASSERT_NOK(backup_engine_->CreateNewBackup(db_.get())); - CloseDBAndBackupEngine(); }