Skip to content

Commit

Permalink
Fixed FileHandleTest.localFile test (#28)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #28

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.

Reviewed By: mbasmanova

Differential Revision: D30262592

fbshipit-source-id: 2aff472d722526f68b6d76282298371d501bc2f7
  • Loading branch information
tanjialiang authored and facebook-github-bot committed Aug 11, 2021
1 parent f2f35c4 commit b66d9d1
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions velox/connectors/hive/FileHandleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,37 @@

#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) {
TEST(FileHandleTest, 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);
remove(filename.data());

{
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");

// Clean up
remove(filename.data());
}

0 comments on commit b66d9d1

Please sign in to comment.