提交 4b7286ad 编写于 作者: P Peter Dillinger 提交者: 奏之章

[cherry pick] update timer test

上级 5a0ac9d1
......@@ -919,7 +919,8 @@ endif()
IF(WITH_TESTS OR WITH_TOOLS)
add_library(testharness OBJECT util/testharness.cc)
add_library(testharness OBJECT util/testharness.cc util/mock_time_env.cc)
target_link_libraries(testharness gtest)
ENDIF()
if(WITH_TESTS)
......
......@@ -609,6 +609,13 @@ cpp_library(
srcs = [
"db/db_test_util.cc",
"table/mock_table.cc",
<<<<<<< HEAD
=======
"test_util/mock_time_env.cc",
"test_util/testharness.cc",
"test_util/testutil.cc",
"tools/block_cache_analyzer/block_cache_trace_analyzer.cc",
>>>>>>> ac1734d06... Fix/minimize mock_time_env.h dependencies (#7426)
"tools/trace_analyzer_tool.cc",
"util/fault_injection_test_env.cc",
"util/testharness.cc",
......
......@@ -926,7 +926,7 @@ void DBImpl::ScheduleGCTTL() {
TEST_SYNC_POINT("DBImpl:ScheduleGCTTL");
uint64_t mark_count = 0;
uint64_t marked_count = 0;
uint64_t nowSeconds = env_->NowMicros() / 1000000;
uint64_t nowSeconds = env_->NowMicros() / 1000U / 1000U;
auto should_marked_for_compacted = [](uint64_t ratio_expire_time,
uint64_t scan_gap_expire_time,
uint64_t now) {
......
......@@ -12,18 +12,22 @@ namespace rocksdb {
class DBImplGCTTL_Test : public DBTestBase {
public:
DBImplGCTTL_Test() : DBTestBase("/db_GC_ttl_test"){
}
void init() {
void init(){
rocksdb::SyncPoint::GetInstance()->SetCallBack(
"DBImpl:ScheduleGCTTL",
[&](void* /*arg*/) { mark = 0;flag = true;});
[&](void* /*arg*/) {
mark = 0;flag = true;
});
rocksdb::SyncPoint::GetInstance()->SetCallBack(
"DBImpl:ScheduleGCTTL-mark",
[&](void* /*arg*/) { mark++;});
SyncPoint::GetInstance()->EnableProcessing();
dbname = test::PerThreadDBPath("ttl_gc_test");
ASSERT_OK(DestroyDB(dbname, options));
DestroyDB(dbname, options);
options.create_if_missing = true;
options.ttl_garbage_collection_percentage = 50.0;
......@@ -32,10 +36,10 @@ class DBImplGCTTL_Test : public DBTestBase {
options.level0_file_num_compaction_trigger = 8;
options.stats_dump_period_sec = 10;
options.table_factory.reset(new BlockBasedTableFactory(BlockBasedTableOptions()));
}
protected:
std::unique_ptr<rocksdb::MockTimeEnv> mock_env;
Options options;
std::string dbname;
bool flag = false;
......@@ -44,14 +48,13 @@ class DBImplGCTTL_Test : public DBTestBase {
TEST_F(DBImplGCTTL_Test, L0FileExpiredTest) {
init();
std::unique_ptr<rocksdb::MockTimeEnv> mock_env;
int L0FilesNums = 4;
uint64_t ttl = 200;
mock_env.reset(new rocksdb::MockTimeEnv(env_));
mock_env->set_current_time(0); // in seconds
mock_env->set_current_time(ttl); // in seconds
options.env = mock_env.get();
Reopen(options);
int L0FilesNums = 4;
uint64_t ttl = 200;
char ts_string[8];
EncodeFixed64(ts_string, ttl);
int KeyEntrys = 800;
......@@ -72,8 +75,6 @@ TEST_F(DBImplGCTTL_Test, L0FileExpiredTest) {
ASSERT_TRUE(flag);
ASSERT_EQ(L0FilesNums,mark);
dbfull()->TEST_WaitForCompact();
dbfull()->Close();
}
} // namespace rocksdb
......
......@@ -6,6 +6,7 @@
#include "db/periodic_work_scheduler.h"
#include "db/db_test_util.h"
#include "util/cast_util.h"
namespace rocksdb {
......
......@@ -314,6 +314,7 @@ TEST_LIB_SOURCES = \
=======
TEST_LIB_SOURCES = \
db/db_test_util.cc \
test_util/mock_time_env.cc \
test_util/testharness.cc \
test_util/testutil.cc \
>>>>>>> 671d15cbd... Persistent Stats: persist stats history to disk (#5046)
......
// 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).
#include "util/mock_time_env.h"
#include "util/sync_point.h"
namespace rocksdb {
// TODO: this is a workaround for the different behavior on different platform
// for timedwait timeout. Ideally timedwait API should be moved to env.
// details: PR #7101.
void MockTimeEnv::InstallTimedWaitFixCallback() {
#ifndef NDEBUG
SyncPoint::GetInstance()->DisableProcessing();
SyncPoint::GetInstance()->ClearAllCallBacks();
#ifdef OS_MACOSX
// This is an alternate way (vs. SpecialEnv) of dealing with the fact
// that on some platforms, pthread_cond_timedwait does not appear to
// release the lock for other threads to operate if the deadline time
// is already passed. (TimedWait calls are currently a bad abstraction
// because the deadline parameter is usually computed from Env time,
// but is interpreted in real clock time.)
SyncPoint::GetInstance()->SetCallBack(
"InstrumentedCondVar::TimedWaitInternal", [&](void* arg) {
uint64_t time_us = *reinterpret_cast<uint64_t*>(arg);
if (time_us < this->RealNowMicros()) {
*reinterpret_cast<uint64_t*>(arg) = this->RealNowMicros() + 1000;
}
});
#endif // OS_MACOSX
SyncPoint::GetInstance()->EnableProcessing();
#endif // !NDEBUG
}
} // namespace ROCKSDB_NAMESPACE
......@@ -5,6 +5,8 @@
#pragma once
#include <atomic>
#include "rocksdb/env.h"
#include "rocksdb/terark_namespace.h"
......@@ -60,29 +62,11 @@ class MockTimeEnv : public EnvWrapper {
// TODO: this is a workaround for the different behavior on different platform
// for timedwait timeout. Ideally timedwait API should be moved to env.
// details: PR #7101.
void InstallTimedWaitFixCallback() {
SyncPoint::GetInstance()->DisableProcessing();
SyncPoint::GetInstance()->ClearAllCallBacks();
#if defined(OS_MACOSX) && !defined(NDEBUG)
// This is an alternate way (vs. SpecialEnv) of dealing with the fact
// that on some platforms, pthread_cond_timedwait does not appear to
// release the lock for other threads to operate if the deadline time
// is already passed. (TimedWait calls are currently a bad abstraction
// because the deadline parameter is usually computed from Env time,
// but is interpreted in real clock time.)
SyncPoint::GetInstance()->SetCallBack(
"InstrumentedCondVar::TimedWaitInternal", [&](void* arg) {
uint64_t time_us = *reinterpret_cast<uint64_t*>(arg);
if (time_us < this->RealNowMicros()) {
*reinterpret_cast<uint64_t*>(arg) = this->RealNowMicros() + 1000;
}
});
#endif // OS_MACOSX && !NDEBUG
SyncPoint::GetInstance()->EnableProcessing();
}
void InstallTimedWaitFixCallback();
private:
std::atomic<uint64_t> current_time_us_{0};
static constexpr uint64_t kMicrosInSecond = 1000U * 1000U;
};
} // namespace TERARKDB_NAMESPACE
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册