Skip to content

Commit

Permalink
Fixed FileHandleTest.localFile test
Browse files Browse the repository at this point in the history
Summary: When running stress tests, multiple process/threads are running the same thing, reading/writing the same file "/tmp/test", which in turn creates a cross process/threads race condition.

Differential Revision: D30262592

fbshipit-source-id: c5a849cbfad75cd3fd9a401128b36a603ccaf497
  • Loading branch information
tanjialiang authored and facebook-github-bot committed Aug 11, 2021
1 parent 894d7de commit f9bdb79
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions velox/connectors/hive/FileHandleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,35 @@

#include "velox/connectors/hive/FileHandle.h"

#include <string>
#include "gtest/gtest.h"
#include "velox/common/caching/SimpleLRUCache.h"
#include "velox/common/file/File.h"
#include "velox/common/memory/Arena.h"

#include "gtest/gtest.h"

using namespace facebook::velox;

TEST(FileHandle, localFile) {
// TODO: use the appropriate test directory.
const char filename[] = "/tmp/test";
remove(filename);
// Use unique name for each process/thread execution to prevent cross
// process/thread race condition
auto pid = getpid();
auto tid = pthread_self();
const std::string filename =
"/tmp/test" + std::to_string(pid) + "_" + std::to_string(tid);

{
LocalWriteFile writeFile(filename);
writeFile.append("foo");
}

FileHandleFactory factory(
std::make_unique<SimpleLRUCache<std::string, FileHandle>>(1000),
std::make_unique<FileHandleGenerator>());
auto fileHandle = factory.generate(filename);
ASSERT_EQ(fileHandle->file->size(), 3);
Arena arena;
ASSERT_EQ(fileHandle->file->pread(0, 3, &arena), "foo");

remove(filename.data());
}

0 comments on commit f9bdb79

Please sign in to comment.