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);
|
||||
}
|
||||
|
||||
class DelayedMergeOperator : public AssociativeMergeOperator {
|
||||
class DelayedMergeOperator : public MergeOperator {
|
||||
private:
|
||||
DBTest* db_test_;
|
||||
|
||||
public:
|
||||
explicit DelayedMergeOperator(DBTest* d) : db_test_(d) {}
|
||||
virtual bool Merge(const Slice& key, const Slice* existing_value,
|
||||
const Slice& value, std::string* new_value,
|
||||
Logger* logger) const override {
|
||||
virtual bool FullMerge(const Slice& key, const Slice* existing_value,
|
||||
const std::deque<std::string>& operand_list,
|
||||
std::string* new_value,
|
||||
Logger* logger) const override {
|
||||
db_test_->env_->addon_time_.fetch_add(1000);
|
||||
*new_value = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -8262,6 +8264,8 @@ TEST_F(DBTest, MergeTestTime) {
|
||||
// Enable time profiling
|
||||
SetPerfLevel(kEnableTime);
|
||||
this->env_->addon_time_.store(0);
|
||||
this->env_->time_elapse_only_sleep_ = true;
|
||||
this->env_->no_sleep_ = true;
|
||||
Options options;
|
||||
options = CurrentOptions(options);
|
||||
options.statistics = rocksdb::CreateDBStatistics();
|
||||
@ -8282,11 +8286,7 @@ TEST_F(DBTest, MergeTestTime) {
|
||||
std::string result;
|
||||
db_->Get(opt, "foo", &result);
|
||||
|
||||
ASSERT_GT(TestGetTickerCount(options, MERGE_OPERATION_TOTAL_TIME), 1200000);
|
||||
// Counter upper bound depends on platform. Just check a conservative
|
||||
// large value.
|
||||
ASSERT_LT(TestGetTickerCount(options, MERGE_OPERATION_TOTAL_TIME),
|
||||
1000000000);
|
||||
ASSERT_EQ(1000000, TestGetTickerCount(options, MERGE_OPERATION_TOTAL_TIME));
|
||||
|
||||
ReadOptions read_options;
|
||||
std::unique_ptr<Iterator> iter(db_->NewIterator(read_options));
|
||||
@ -8297,15 +8297,11 @@ TEST_F(DBTest, MergeTestTime) {
|
||||
}
|
||||
|
||||
ASSERT_EQ(1, count);
|
||||
|
||||
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);
|
||||
ASSERT_EQ(2000000, TestGetTickerCount(options, MERGE_OPERATION_TOTAL_TIME));
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
ASSERT_GT(TestGetTickerCount(options, FLUSH_WRITE_BYTES), 0);
|
||||
#endif // ROCKSDB_USING_THREAD_STATUS
|
||||
this->env_->time_elapse_only_sleep_ = false;
|
||||
}
|
||||
|
||||
#ifndef ROCKSDB_LITE
|
||||
|
@ -327,15 +327,19 @@ class SpecialEnv : public EnvWrapper {
|
||||
|
||||
virtual void SleepForMicroseconds(int micros) override {
|
||||
sleep_counter_.Increment();
|
||||
if (no_sleep_) {
|
||||
if (no_sleep_ || time_elapse_only_sleep_) {
|
||||
addon_time_.fetch_add(micros);
|
||||
} else {
|
||||
}
|
||||
if (!no_sleep_) {
|
||||
target()->SleepForMicroseconds(micros);
|
||||
}
|
||||
}
|
||||
|
||||
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()) {
|
||||
*unix_time += addon_time_.load();
|
||||
}
|
||||
@ -343,11 +347,13 @@ class SpecialEnv : public EnvWrapper {
|
||||
}
|
||||
|
||||
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 {
|
||||
return target()->NowMicros() + addon_time_.load();
|
||||
return (time_elapse_only_sleep_ ? 0 : target()->NowMicros()) +
|
||||
addon_time_.load();
|
||||
}
|
||||
|
||||
Random rnd_;
|
||||
@ -399,6 +405,9 @@ class SpecialEnv : public EnvWrapper {
|
||||
std::function<void()>* table_write_callback_;
|
||||
|
||||
std::atomic<int64_t> addon_time_;
|
||||
|
||||
bool time_elapse_only_sleep_;
|
||||
|
||||
bool no_sleep_;
|
||||
|
||||
std::atomic<bool> is_wal_sync_thread_safe_{true};
|
||||
|
Loading…
Reference in New Issue
Block a user