Skip to content

Commit

Permalink
Fix flaky trace dir create test (facebookincubator#10874)
Browse files Browse the repository at this point in the history
Summary:
Lock is required for multithreading update the created trace directory, verified the fix
in Meta test infra

Pull Request resolved: facebookincubator#10874

Reviewed By: spershin

Differential Revision: D61897242

Pulled By: xiaoxmeng

fbshipit-source-id: 1662388e256d7add8abc05de6faf7b6a00c8f972
  • Loading branch information
xiaoxmeng authored and facebook-github-bot committed Aug 28, 2024
1 parent db8875c commit d76b6d1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions velox/exec/trace/test/QueryTraceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,21 @@ TEST_F(QueryTracerTest, traceDir) {
fs->mkdir(parentDir);

constexpr auto numThreads = 5;
std::vector<std::thread> queryThreads;
queryThreads.reserve(numThreads);
std::vector<std::thread> traceThreads;
traceThreads.reserve(numThreads);
std::mutex mutex;
std::set<std::string> expectedDirs;
for (int i = 0; i < numThreads; ++i) {
queryThreads.emplace_back([&, i]() {
traceThreads.emplace_back([&, i]() {
const auto dir = fmt::format("{}/s{}", parentDir, i);
trace::createTraceDirectory(dir);
std::lock_guard<std::mutex> l(mutex);
expectedDirs.insert(dir);
});
}

for (auto& queryThread : queryThreads) {
queryThread.join();
for (auto& traceThread : traceThreads) {
traceThread.join();
}

const auto actualDirs = fs->list(parentDir);
Expand Down

0 comments on commit d76b6d1

Please sign in to comment.