Make db_test more robust

Summary: While working on D13239, I noticed that the same options are not used for opening and destroying at db. So adding that. Also added asserts for successful DestroyDB calls.

Test Plan: Ran unit tests. Atleast 1 unit test is failing. They failures are a result of some past logic change. I'm not really planning to fix those. But I would like to check this in. And hopefully the respective unit test owners can fix the broken tests

Reviewers: leveldb, haobo

CC: xinyaohu, sumeet, dhruba

Differential Revision: https://reviews.facebook.net/D13329
This commit is contained in:
Naman Gupta 2013-10-04 10:21:03 -07:00
parent 1f8ade6bd6
commit 116071411b

View File

@ -249,7 +249,7 @@ class DBTest {
env_(new SpecialEnv(Env::Default())) { env_(new SpecialEnv(Env::Default())) {
filter_policy_ = NewBloomFilterPolicy(10); filter_policy_ = NewBloomFilterPolicy(10);
dbname_ = test::TmpDir() + "/db_test"; dbname_ = test::TmpDir() + "/db_test";
DestroyDB(dbname_, Options()); ASSERT_OK(DestroyDB(dbname_, Options()));
db_ = nullptr; db_ = nullptr;
Reopen(); Reopen();
} }
@ -277,6 +277,7 @@ class DBTest {
} }
if (option_config_ >= kEnd) { if (option_config_ >= kEnd) {
Destroy(&last_options_);
return false; return false;
} else { } else {
DestroyAndReopen(); DestroyAndReopen();
@ -285,10 +286,10 @@ class DBTest {
} }
// Switch between different compaction styles (we have only 2 now). // Switch between different compaction styles (we have only 2 now).
bool ChangeCompactOptions() { bool ChangeCompactOptions(Options* options = nullptr) {
if (option_config_ == kDefault) { if (option_config_ == kDefault) {
option_config_ = kUniversalCompaction; option_config_ = kUniversalCompaction;
DestroyAndReopen(); DestroyAndReopen(options);
return true; return true;
} else { } else {
return false; return false;
@ -321,7 +322,8 @@ class DBTest {
case kManifestFileSize: case kManifestFileSize:
options.max_manifest_file_size = 50; // 50 bytes options.max_manifest_file_size = 50; // 50 bytes
case kCompactOnFlush: case kCompactOnFlush:
options.purge_redundant_kvs_while_flush = !options.purge_redundant_kvs_while_flush; options.purge_redundant_kvs_while_flush =
!options.purge_redundant_kvs_while_flush;
break; break;
case kPerfOptions: case kPerfOptions:
options.hard_rate_limit = 2.0; options.hard_rate_limit = 2.0;
@ -360,10 +362,15 @@ class DBTest {
} }
void DestroyAndReopen(Options* options = nullptr) { void DestroyAndReopen(Options* options = nullptr) {
//Destroy using last options
Destroy(&last_options_);
ASSERT_OK(TryReopen(options));
}
void Destroy(Options* options) {
delete db_; delete db_;
db_ = nullptr; db_ = nullptr;
DestroyDB(dbname_, Options()); DestroyDB(dbname_, *options);
ASSERT_OK(TryReopen(options));
} }
Status PureReopen(Options* options, DB** db) { Status PureReopen(Options* options, DB** db) {
@ -599,7 +606,7 @@ class DBTest {
const SequenceNumber seq) { const SequenceNumber seq) {
unique_ptr<TransactionLogIterator> iter; unique_ptr<TransactionLogIterator> iter;
Status status = dbfull()->GetUpdatesSince(seq, &iter); Status status = dbfull()->GetUpdatesSince(seq, &iter);
ASSERT_TRUE(status.ok()); ASSERT_OK(status);
ASSERT_TRUE(iter->Valid()); ASSERT_TRUE(iter->Valid());
return std::move(iter); return std::move(iter);
} }
@ -904,7 +911,7 @@ TEST(DBTest, NonBlockingIteration) {
Iterator* iter = db_->NewIterator(non_blocking_opts); Iterator* iter = db_->NewIterator(non_blocking_opts);
int count = 0; int count = 0;
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
ASSERT_TRUE(iter->status().ok()); ASSERT_OK(iter->status());
count++; count++;
} }
ASSERT_EQ(count, 1); ASSERT_EQ(count, 1);
@ -940,7 +947,7 @@ TEST(DBTest, NonBlockingIteration) {
iter = db_->NewIterator(non_blocking_opts); iter = db_->NewIterator(non_blocking_opts);
count = 0; count = 0;
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
ASSERT_TRUE(iter->status().ok()); ASSERT_OK(iter->status());
count++; count++;
} }
ASSERT_EQ(count, 1); ASSERT_EQ(count, 1);
@ -1397,10 +1404,10 @@ TEST(DBTest, CheckLock) {
do { do {
DB* localdb; DB* localdb;
Options options = CurrentOptions(); Options options = CurrentOptions();
ASSERT_TRUE(TryReopen(&options).ok()); ASSERT_OK(TryReopen(&options));
// second open should fail // second open should fail
ASSERT_TRUE(!(PureReopen(&options, &localdb).ok())); ASSERT_TRUE(!(PureReopen(&options, &localdb)).ok());
} while (ChangeCompactOptions()); } while (ChangeCompactOptions());
} }
@ -2226,7 +2233,7 @@ TEST(DBTest, CompactionFilter) {
int total = 0; int total = 0;
Iterator* iter = dbfull()->TEST_NewInternalIterator(); Iterator* iter = dbfull()->TEST_NewInternalIterator();
iter->SeekToFirst(); iter->SeekToFirst();
ASSERT_EQ(iter->status().ok(), true); ASSERT_OK(iter->status());
while (iter->Valid()) { while (iter->Valid()) {
ParsedInternalKey ikey; ParsedInternalKey ikey;
ikey.sequence = -1; ikey.sequence = -1;
@ -2311,7 +2318,7 @@ TEST(DBTest, CompactionFilter) {
count = 0; count = 0;
iter = dbfull()->TEST_NewInternalIterator(); iter = dbfull()->TEST_NewInternalIterator();
iter->SeekToFirst(); iter->SeekToFirst();
ASSERT_EQ(iter->status().ok(), true); ASSERT_OK(iter->status());
while (iter->Valid()) { while (iter->Valid()) {
ParsedInternalKey ikey; ParsedInternalKey ikey;
ASSERT_EQ(ParseInternalKey(iter->key(), &ikey), true); ASSERT_EQ(ParseInternalKey(iter->key(), &ikey), true);
@ -2715,7 +2722,7 @@ TEST(DBTest, OverlapInLevel0) {
int tmp = dbfull()->MaxMemCompactionLevel(); int tmp = dbfull()->MaxMemCompactionLevel();
ASSERT_EQ(tmp, 2) << "Fix test to match config"; ASSERT_EQ(tmp, 2) << "Fix test to match config";
// Fill levels 1 and 2 to disable the pushing of new memtables to levels > 0. //Fill levels 1 and 2 to disable the pushing of new memtables to levels > 0.
ASSERT_OK(Put("100", "v100")); ASSERT_OK(Put("100", "v100"));
ASSERT_OK(Put("999", "v999")); ASSERT_OK(Put("999", "v999"));
dbfull()->TEST_CompactMemTable(); dbfull()->TEST_CompactMemTable();
@ -2919,7 +2926,7 @@ TEST(DBTest, ManualCompaction) {
TEST(DBTest, DBOpen_Options) { TEST(DBTest, DBOpen_Options) {
std::string dbname = test::TmpDir() + "/db_options_test"; std::string dbname = test::TmpDir() + "/db_options_test";
DestroyDB(dbname, Options()); ASSERT_OK(DestroyDB(dbname, Options()));
// Does not exist, and create_if_missing == false: error // Does not exist, and create_if_missing == false: error
DB* db = nullptr; DB* db = nullptr;
@ -2958,7 +2965,7 @@ TEST(DBTest, DBOpen_Options) {
TEST(DBTest, DBOpen_Change_NumLevels) { TEST(DBTest, DBOpen_Change_NumLevels) {
std::string dbname = test::TmpDir() + "/db_change_num_levels"; std::string dbname = test::TmpDir() + "/db_change_num_levels";
DestroyDB(dbname, Options()); ASSERT_OK(DestroyDB(dbname, Options()));
Options opts; Options opts;
Status s; Status s;
DB* db = nullptr; DB* db = nullptr;
@ -2985,9 +2992,9 @@ TEST(DBTest, DestroyDBMetaDatabase) {
std::string metametadbname = MetaDatabaseName(metadbname, 0); std::string metametadbname = MetaDatabaseName(metadbname, 0);
// Destroy previous versions if they exist. Using the long way. // Destroy previous versions if they exist. Using the long way.
DestroyDB(metametadbname, Options()); ASSERT_OK(DestroyDB(metametadbname, Options()));
DestroyDB(metadbname, Options()); ASSERT_OK(DestroyDB(metadbname, Options()));
DestroyDB(dbname, Options()); ASSERT_OK(DestroyDB(dbname, Options()));
// Setup databases // Setup databases
Options opts; Options opts;
@ -3004,13 +3011,13 @@ TEST(DBTest, DestroyDBMetaDatabase) {
db = nullptr; db = nullptr;
// Delete databases // Delete databases
DestroyDB(dbname, Options()); ASSERT_OK(DestroyDB(dbname, Options()));
// Check if deletion worked. // Check if deletion worked.
opts.create_if_missing = false; opts.create_if_missing = false;
ASSERT_TRUE(!DB::Open(opts, dbname, &db).ok()); ASSERT_TRUE(!(DB::Open(opts, dbname, &db)).ok());
ASSERT_TRUE(!DB::Open(opts, metadbname, &db).ok()); ASSERT_TRUE(!(DB::Open(opts, metadbname, &db)).ok());
ASSERT_TRUE(!DB::Open(opts, metametadbname, &db).ok()); ASSERT_TRUE(!(DB::Open(opts, metametadbname, &db)).ok());
} }
// Check that number of files does not grow when we are out of space // Check that number of files does not grow when we are out of space
@ -3249,7 +3256,7 @@ TEST(DBTest, SnapshotFiles) {
DB* snapdb; DB* snapdb;
opts.create_if_missing = false; opts.create_if_missing = false;
Status stat = DB::Open(opts, snapdir, &snapdb); Status stat = DB::Open(opts, snapdir, &snapdb);
ASSERT_TRUE(stat.ok()); ASSERT_OK(stat);
ReadOptions roptions; ReadOptions roptions;
std::string val; std::string val;
@ -3471,7 +3478,7 @@ void ExpectRecords(
ASSERT_TRUE(res.sequence > lastSequence); ASSERT_TRUE(res.sequence > lastSequence);
++i; ++i;
lastSequence = res.sequence; lastSequence = res.sequence;
ASSERT_TRUE(iter->status().ok()); ASSERT_OK(iter->status());
iter->Next(); iter->Next();
} }
ASSERT_EQ(i, expected_no_records); ASSERT_EQ(i, expected_no_records);
@ -4234,7 +4241,7 @@ TEST(DBTest, PrefixScan) {
assert(iter->key().starts_with(prefix)); assert(iter->key().starts_with(prefix));
count++; count++;
} }
ASSERT_TRUE(iter->status().ok()); ASSERT_OK(iter->status());
delete iter; delete iter;
ASSERT_EQ(count, 2); ASSERT_EQ(count, 2);
ASSERT_EQ(env_->random_read_counter_.Read(), 2); ASSERT_EQ(env_->random_read_counter_.Read(), 2);
@ -4251,7 +4258,7 @@ TEST(DBTest, PrefixScan) {
assert(iter->key().starts_with(prefix)); assert(iter->key().starts_with(prefix));
count++; count++;
} }
ASSERT_TRUE(iter->status().ok()); ASSERT_OK(iter->status());
delete iter; delete iter;
ASSERT_EQ(count, 2); ASSERT_EQ(count, 2);
ASSERT_EQ(env_->random_read_counter_.Read(), 2); ASSERT_EQ(env_->random_read_counter_.Read(), 2);
@ -4268,7 +4275,7 @@ TEST(DBTest, PrefixScan) {
} }
count++; count++;
} }
ASSERT_TRUE(iter->status().ok()); ASSERT_OK(iter->status());
delete iter; delete iter;
ASSERT_EQ(count, 2); ASSERT_EQ(count, 2);
ASSERT_EQ(env_->random_read_counter_.Read(), 11); ASSERT_EQ(env_->random_read_counter_.Read(), 11);
@ -4284,7 +4291,7 @@ std::string MakeKey(unsigned int num) {
void BM_LogAndApply(int iters, int num_base_files) { void BM_LogAndApply(int iters, int num_base_files) {
std::string dbname = test::TmpDir() + "/rocksdb_test_benchmark"; std::string dbname = test::TmpDir() + "/rocksdb_test_benchmark";
DestroyDB(dbname, Options()); ASSERT_OK(DestroyDB(dbname, Options()));
DB* db = nullptr; DB* db = nullptr;
Options opts; Options opts;