Skip to content

Commit

Permalink
prevent stranded LATEST_BACKUP in BackupEngineTest.NoDeleteWithReadOn…
Browse files Browse the repository at this point in the history
…ly (facebook#8887)

Summary:
A "LATEST_BACKUP" file was left in the backup directory by
"BackupEngineTest.NoDeleteWithReadOnly" test, affecting future test
runs. In particular, it caused "BackupEngineTest.IOStats" to fail since
it relies on backup directory containing only data written by its
`BackupEngine`.

The fix is to promote "LATEST_BACKUP" to an explicitly managed file so
it is deleted in `BackupEngineTest` constructor if it exists.

Pull Request resolved: facebook#8887

Test Plan:
below command used to fail. Now it passes:

```
$ TEST_TMPDIR=/dev/shm ./backupable_db_test --gtest_filter='BackupEngineTest.NoDeleteWithReadOnly:BackupEngineTest.IOStats'
```

Reviewed By: pdillinger

Differential Revision: D30812336

Pulled By: ajkr

fbshipit-source-id: 32dfbe1368ebdab872e610764bfea5daf9a2af09
  • Loading branch information
ajkr authored and facebook-github-bot committed Sep 8, 2021
1 parent 91b95ca commit dd092c2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion utilities/backupable/backupable_db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ class BackupEngineTest : public testing::Test {
EXPECT_OK(Env::Default()->CreateDirIfMissing(backup_chroot));
dbname_ = "/tempdb";
backupdir_ = "/tempbk";
latest_backup_ = backupdir_ + "/LATEST_BACKUP";

// set up envs
db_chroot_env_.reset(NewChrootEnv(Env::Default(), db_chroot));
Expand Down Expand Up @@ -663,6 +664,10 @@ class BackupEngineTest : public testing::Test {

// delete old files in db
DestroyDB(dbname_, options_);

// delete old LATEST_BACKUP file, which some tests create for compatibility
// testing.
backup_chroot_env_->DeleteFile(latest_backup_).PermitUncheckedError();
}

DB* OpenDB() {
Expand Down Expand Up @@ -943,6 +948,7 @@ class BackupEngineTest : public testing::Test {
// files
std::string dbname_;
std::string backupdir_;
std::string latest_backup_;

// logger_ must be above backup_engine_ such that the engine's destructor,
// which uses a raw pointer to the logger, executes first.
Expand Down Expand Up @@ -1853,7 +1859,7 @@ TEST_F(BackupEngineTest, NoDeleteWithReadOnly) {
ASSERT_OK(backup_engine_->CreateNewBackup(db_.get(), !!(rnd.Next() % 2)));
}
CloseDBAndBackupEngine();
ASSERT_OK(file_manager_->WriteToFile(backupdir_ + "/LATEST_BACKUP", "4"));
ASSERT_OK(file_manager_->WriteToFile(latest_backup_, "4"));

backupable_options_->destroy_old_data = false;
BackupEngineReadOnly* read_only_backup_engine;
Expand Down

0 comments on commit dd092c2

Please sign in to comment.