mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-30 04:41:49 +00:00
933250e355
Summary: When `MockTimeEnv` is used in test to mock time methods, we cannot use `CondVar::TimedWait` because it is using real time, not the mocked time for wait timeout. On Mac the method can return immediately without awaking other waiting threads, if the real time is larger than `wait_until` (which is a mocked time). When that happen, the `wait()` method will fall into an infinite loop. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4560 Differential Revision: D10472851 Pulled By: yiwu-arbug fbshipit-source-id: 898902546ace7db7ac509337dd8677a527209d19
44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#pragma once
|
|
|
|
#include "rocksdb/env.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
class MockTimeEnv : public EnvWrapper {
|
|
public:
|
|
explicit MockTimeEnv(Env* base) : EnvWrapper(base) {}
|
|
|
|
virtual Status GetCurrentTime(int64_t* time) override {
|
|
assert(time != nullptr);
|
|
assert(current_time_ <=
|
|
static_cast<uint64_t>(std::numeric_limits<int64_t>::max()));
|
|
*time = static_cast<int64_t>(current_time_);
|
|
return Status::OK();
|
|
}
|
|
|
|
virtual uint64_t NowMicros() override {
|
|
assert(current_time_ <= std::numeric_limits<uint64_t>::max() / 1000000);
|
|
return current_time_ * 1000000;
|
|
}
|
|
|
|
virtual uint64_t NowNanos() override {
|
|
assert(current_time_ <= std::numeric_limits<uint64_t>::max() / 1000000000);
|
|
return current_time_ * 1000000000;
|
|
}
|
|
|
|
void set_current_time(uint64_t time) {
|
|
assert(time >= current_time_);
|
|
current_time_ = time;
|
|
}
|
|
|
|
private:
|
|
std::atomic<uint64_t> current_time_{0};
|
|
};
|
|
|
|
} // namespace rocksdb
|