From 9418403c4ba7954e837d318b931e631b36dbb709 Mon Sep 17 00:00:00 2001 From: Jay Zhuang Date: Tue, 30 Mar 2021 16:50:17 -0700 Subject: [PATCH] Unittest uses unique test db name (#8124) Summary: thread_id is only unique within a process. If we run the same test-set with multiple processes, it could cause db path collision between 2 runs, error message will be like: ``` ... IO error: While lock file: /tmp/rocksdbtest-501//deletefile_test_8093137327721791717/LOCK: Resource temporarily unavailable ... ``` This is could be likely reproduced by: ``` gtest-parallel ./deletefile_test --gtest_filter=DeleteFileTest.BackgroundPurgeCFDropTest -r 1000 -w 1000 ``` Pull Request resolved: https://github.com/facebook/rocksdb/pull/8124 Reviewed By: ajkr Differential Revision: D27435195 Pulled By: jay-zhuang fbshipit-source-id: 850fc72cdb660edf93be9a1ca9327008c16dd720 --- test_util/testharness.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test_util/testharness.cc b/test_util/testharness.cc index 50e105c51..d8650dafb 100644 --- a/test_util/testharness.cc +++ b/test_util/testharness.cc @@ -14,6 +14,14 @@ namespace ROCKSDB_NAMESPACE { namespace test { +#ifdef OS_WIN +#include + +std::string GetPidStr() { return std::to_string(GetCurrentProcessId()); } +#else +std::string GetPidStr() { return std::to_string(getpid()); } +#endif + ::testing::AssertionResult AssertStatus(const char* s_expr, const Status& s) { if (s.ok()) { return ::testing::AssertionSuccess(); @@ -32,7 +40,7 @@ std::string TmpDir(Env* env) { std::string PerThreadDBPath(std::string dir, std::string name) { size_t tid = std::hash()(std::this_thread::get_id()); - return dir + "/" + name + "_" + std::to_string(tid); + return dir + "/" + name + "_" + GetPidStr() + "_" + std::to_string(tid); } std::string PerThreadDBPath(std::string name) { -- GitLab