Skip to content

Commit 42cbea6

Browse files
author
Orri Erling
committed
refactor: Make tests composable
Inherits the gtest test virtually to llow combining test base classes. Allows specifying an extrermal path for LocalRunnerTestBase.
1 parent cb29c36 commit 42cbea6

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

velox/exec/tests/utils/LocalRunnerTestBase.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void LocalRunnerTestBase::setupConnector() {
6060
connector::unregisterConnector(kHiveConnectorId);
6161

6262
std::unordered_map<std::string, std::string> configs;
63-
configs[connector::hive::HiveConfig::kLocalDataPath] = files_->getPath();
63+
configs[connector::hive::HiveConfig::kLocalDataPath] = testDataPath_;
6464
configs[connector::hive::HiveConfig::kLocalFileFormat] = "dwrf";
6565
auto hiveConnector =
6666
connector::getConnectorFactory(
@@ -75,9 +75,16 @@ void LocalRunnerTestBase::setupConnector() {
7575
void LocalRunnerTestBase::makeTables(
7676
std::vector<TableSpec> specs,
7777
std::shared_ptr<TempDirectoryPath>& directory) {
78-
directory = exec::test::TempDirectoryPath::create();
78+
if (initialized_) {
79+
return;
80+
}
81+
initialized_ = true;
82+
if (testDataPath_.empty()) {
83+
directory = exec::test::TempDirectoryPath::create();
84+
testDataPath_ = directory->getPath();
85+
}
7986
for (auto& spec : specs) {
80-
auto tablePath = fmt::format("{}/{}", directory->getPath(), spec.name);
87+
auto tablePath = fmt::format("{}/{}", testDataPath_, spec.name);
8188
auto fs = filesystems::getFileSystem(tablePath, {});
8289
fs->mkdir(tablePath);
8390
for (auto i = 0; i < spec.numFiles; ++i) {

velox/exec/tests/utils/LocalRunnerTestBase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class LocalRunnerTestBase : public HiveConnectorTestBase {
4747
}
4848

4949
static void TearDownTestCase() {
50+
initialized_ = false;
5051
files_.reset();
5152
HiveConnectorTestBase::TearDownTestCase();
5253
}
@@ -84,6 +85,8 @@ class LocalRunnerTestBase : public HiveConnectorTestBase {
8485
inline static std::vector<TableSpec> testTables_;
8586

8687
// The top level directory with the test data.
88+
inline static bool initialized_;
89+
inline static std::string testDataPath_;
8790
inline static std::shared_ptr<TempDirectoryPath> files_;
8891
/// Map from table name to list of file system paths.
8992
inline static std::unordered_map<std::string, std::vector<std::string>>

velox/exec/tests/utils/OperatorTestBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "velox/vector/tests/utils/VectorTestBase.h"
2929

3030
namespace facebook::velox::exec::test {
31-
class OperatorTestBase : public testing::Test,
31+
class OperatorTestBase : public virtual testing::Test,
3232
public velox::test::VectorTestBase {
3333
public:
3434
/// The following methods are used by google unit test framework to do

0 commit comments

Comments
 (0)