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
This commit is contained in:
Jay Zhuang 2021-03-30 16:50:17 -07:00 committed by Facebook GitHub Bot
parent f03606cd5c
commit 9418403c4b

View File

@ -14,6 +14,14 @@
namespace ROCKSDB_NAMESPACE {
namespace test {
#ifdef OS_WIN
#include <windows.h>
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::thread::id>()(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) {