DBTest.MergeTestTime to only use fake time to be determinstic
Summary: DBTest.MergeTestTime is a test verifying timing counters. Depending on real time may cause non-determinstic results. Change to fake time to be determinsitic. Test Plan: Run the test and make sure it passes Reviewers: yhchiang, anthony, rven, kradhakrishnan, IslamAbdelRahman Reviewed By: IslamAbdelRahman Subscribers: leveldb, dhruba Differential Revision: https://reviews.facebook.net/D50883
This commit is contained in:
parent
4189c0f9aa
commit
d5540e18e6
@ -8237,16 +8237,18 @@ TEST_F(DBTest, CloseSpeedup) {
|
|||||||
Destroy(options);
|
Destroy(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DelayedMergeOperator : public AssociativeMergeOperator {
|
class DelayedMergeOperator : public MergeOperator {
|
||||||
private:
|
private:
|
||||||
DBTest* db_test_;
|
DBTest* db_test_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DelayedMergeOperator(DBTest* d) : db_test_(d) {}
|
explicit DelayedMergeOperator(DBTest* d) : db_test_(d) {}
|
||||||
virtual bool Merge(const Slice& key, const Slice* existing_value,
|
virtual bool FullMerge(const Slice& key, const Slice* existing_value,
|
||||||
const Slice& value, std::string* new_value,
|
const std::deque<std::string>& operand_list,
|
||||||
|
std::string* new_value,
|
||||||
Logger* logger) const override {
|
Logger* logger) const override {
|
||||||
db_test_->env_->addon_time_.fetch_add(1000);
|
db_test_->env_->addon_time_.fetch_add(1000);
|
||||||
|
*new_value = "";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8262,6 +8264,8 @@ TEST_F(DBTest, MergeTestTime) {
|
|||||||
// Enable time profiling
|
// Enable time profiling
|
||||||
SetPerfLevel(kEnableTime);
|
SetPerfLevel(kEnableTime);
|
||||||
this->env_->addon_time_.store(0);
|
this->env_->addon_time_.store(0);
|
||||||
|
this->env_->time_elapse_only_sleep_ = true;
|
||||||
|
this->env_->no_sleep_ = true;
|
||||||
Options options;
|
Options options;
|
||||||
options = CurrentOptions(options);
|
options = CurrentOptions(options);
|
||||||
options.statistics = rocksdb::CreateDBStatistics();
|
options.statistics = rocksdb::CreateDBStatistics();
|
||||||
@ -8282,11 +8286,7 @@ TEST_F(DBTest, MergeTestTime) {
|
|||||||
std::string result;
|
std::string result;
|
||||||
db_->Get(opt, "foo", &result);
|
db_->Get(opt, "foo", &result);
|
||||||
|
|
||||||
ASSERT_GT(TestGetTickerCount(options, MERGE_OPERATION_TOTAL_TIME), 1200000);
|
ASSERT_EQ(1000000, TestGetTickerCount(options, MERGE_OPERATION_TOTAL_TIME));
|
||||||
// Counter upper bound depends on platform. Just check a conservative
|
|
||||||
// large value.
|
|
||||||
ASSERT_LT(TestGetTickerCount(options, MERGE_OPERATION_TOTAL_TIME),
|
|
||||||
1000000000);
|
|
||||||
|
|
||||||
ReadOptions read_options;
|
ReadOptions read_options;
|
||||||
std::unique_ptr<Iterator> iter(db_->NewIterator(read_options));
|
std::unique_ptr<Iterator> iter(db_->NewIterator(read_options));
|
||||||
@ -8297,15 +8297,11 @@ TEST_F(DBTest, MergeTestTime) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_EQ(1, count);
|
ASSERT_EQ(1, count);
|
||||||
|
ASSERT_EQ(2000000, TestGetTickerCount(options, MERGE_OPERATION_TOTAL_TIME));
|
||||||
ASSERT_GT(TestGetTickerCount(options, MERGE_OPERATION_TOTAL_TIME), 3200000);
|
|
||||||
// Counter upper bound depends on platform. Just check a conservative
|
|
||||||
// large value.
|
|
||||||
ASSERT_LT(TestGetTickerCount(options, MERGE_OPERATION_TOTAL_TIME),
|
|
||||||
1000000000);
|
|
||||||
#if ROCKSDB_USING_THREAD_STATUS
|
#if ROCKSDB_USING_THREAD_STATUS
|
||||||
ASSERT_GT(TestGetTickerCount(options, FLUSH_WRITE_BYTES), 0);
|
ASSERT_GT(TestGetTickerCount(options, FLUSH_WRITE_BYTES), 0);
|
||||||
#endif // ROCKSDB_USING_THREAD_STATUS
|
#endif // ROCKSDB_USING_THREAD_STATUS
|
||||||
|
this->env_->time_elapse_only_sleep_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef ROCKSDB_LITE
|
#ifndef ROCKSDB_LITE
|
||||||
|
@ -327,15 +327,19 @@ class SpecialEnv : public EnvWrapper {
|
|||||||
|
|
||||||
virtual void SleepForMicroseconds(int micros) override {
|
virtual void SleepForMicroseconds(int micros) override {
|
||||||
sleep_counter_.Increment();
|
sleep_counter_.Increment();
|
||||||
if (no_sleep_) {
|
if (no_sleep_ || time_elapse_only_sleep_) {
|
||||||
addon_time_.fetch_add(micros);
|
addon_time_.fetch_add(micros);
|
||||||
} else {
|
}
|
||||||
|
if (!no_sleep_) {
|
||||||
target()->SleepForMicroseconds(micros);
|
target()->SleepForMicroseconds(micros);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Status GetCurrentTime(int64_t* unix_time) override {
|
virtual Status GetCurrentTime(int64_t* unix_time) override {
|
||||||
Status s = target()->GetCurrentTime(unix_time);
|
Status s;
|
||||||
|
if (!time_elapse_only_sleep_) {
|
||||||
|
s = target()->GetCurrentTime(unix_time);
|
||||||
|
}
|
||||||
if (s.ok()) {
|
if (s.ok()) {
|
||||||
*unix_time += addon_time_.load();
|
*unix_time += addon_time_.load();
|
||||||
}
|
}
|
||||||
@ -343,11 +347,13 @@ class SpecialEnv : public EnvWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual uint64_t NowNanos() override {
|
virtual uint64_t NowNanos() override {
|
||||||
return target()->NowNanos() + addon_time_.load() * 1000;
|
return (time_elapse_only_sleep_ ? 0 : target()->NowNanos()) +
|
||||||
|
addon_time_.load() * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint64_t NowMicros() override {
|
virtual uint64_t NowMicros() override {
|
||||||
return target()->NowMicros() + addon_time_.load();
|
return (time_elapse_only_sleep_ ? 0 : target()->NowMicros()) +
|
||||||
|
addon_time_.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
Random rnd_;
|
Random rnd_;
|
||||||
@ -399,6 +405,9 @@ class SpecialEnv : public EnvWrapper {
|
|||||||
std::function<void()>* table_write_callback_;
|
std::function<void()>* table_write_callback_;
|
||||||
|
|
||||||
std::atomic<int64_t> addon_time_;
|
std::atomic<int64_t> addon_time_;
|
||||||
|
|
||||||
|
bool time_elapse_only_sleep_;
|
||||||
|
|
||||||
bool no_sleep_;
|
bool no_sleep_;
|
||||||
|
|
||||||
std::atomic<bool> is_wal_sync_thread_safe_{true};
|
std::atomic<bool> is_wal_sync_thread_safe_{true};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user