10000 Some cleanup for new executor test code, which accidentally fixes ASAN failures in ExecutorTestHelper by markuspf · Pull Request #11283 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Some cleanup for new executor test code, which accidentally fixes ASAN failures in ExecutorTestHelper #11283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions tests/Aql/AqlExecutorTestCase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2020 ArangoDB GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
////////////////////////////////////////////////////////////////////////////////

#include "AqlExecutorTestCase.h"

using namespace arangodb::tests::aql;

template <bool enableQueryTrace>
AqlExecutorTestCase<enableQueryTrace>::AqlExecutorTestCase()
: fakedQuery{_server->createFakeQuery(enableQueryTrace)} {
auto engine = std::make_unique<ExecutionEngine>(*fakedQuery, SerializationFormat::SHADOWROWS);
fakedQuery->setEngine(engine.release());
if constexpr (enableQueryTrace) {
Logger::QUERIES.setLogLevel(LogLevel::DEBUG);
}
}

template <bool enableQueryTrace>
AqlExecutorTestCase<enableQueryTrace>::~AqlExecutorTestCase() {
if constexpr (enableQueryTrace) {
Logger::QUERIES.setLogLevel(LogLevel::INFO);
}
}

template <bool enableQueryTrace>
auto AqlExecutorTestCase<enableQueryTrace>::generateNodeDummy() -> ExecutionNode* {
auto dummy = std::make_unique<SingletonNode>(fakedQuery->plan(), _execNodes.size());
auto res = dummy.get();
_execNodes.emplace_back(std::move(dummy));
return res;
}
template <bool enableQueryTrace>
auto AqlExecutorTestCase<enableQueryTrace>::manager() const -> AqlItemBlockManager& {
return fakedQuery->engine()->itemBlockManager();
}

template class ::arangodb::tests::aql::AqlExecutorTestCase<true>;
template class ::arangodb::tests::aql::AqlExecutorTestCase<false>;
104 changes: 104 additions & 0 deletions tests/Aql/AqlExecutorTestCase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2020 ArangoDB GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
////////////////////////////////////////////////////////////////////////////////

#ifndef TESTS_AQL_EXECUTORTESTCASE_H
#define TESTS_AQL_EXECUTORTESTCASE_H

#include "gtest/gtest.h"

#include "ExecutorTestHelper.h"

#include "Aql/AqlItemBlockManager.h"
#include "Aql/ExecutionNode.h"

#include "Mocks/Servers.h"

using namespace arangodb::aql;
using namespace arangodb::tests::aql;

namespace arangodb {
namespace tests {
namespace aql {

/**
* @brief Base class for ExecutorTests in Aql.
* It will provide a test server, including
* an AqlQuery, as well as the ability to generate
* Dummy ExecutionNodes.
*
* @tparam enableQueryTrace Enable Aql Profile Trace logging
*/
template <bool enableQueryTrace = false>
class AqlExecutorTestCase : public ::testing::Test {
public:
// Creating a server instance costs a lot of time, so do it only once.
// Note that newer version of gtest call these SetUpTestSuite/TearDownTestSuite
static void SetUpTestCase() {
_server = std::make_unique<mocks::MockAqlServer>();
}

static void TearDownTestCase() { _server.reset(); }

protected:
AqlExecutorTestCase();
virtual ~AqlExecutorTestCase();

/**
* @brief Creates and manages a ExecutionNode.
* These nodes can be used to create the Executors
* Caller does not need to manage the memory.
*
* @return ExecutionNode* Pointer to a dummy ExecutionNode. Memory is managed, do not delete.
*/
auto generateNodeDummy() -> ExecutionNode*;

auto manager() const -> AqlItemBlockManager&;

template <std::size_t inputColumns = 1, std::size_t outputColumns = 1>
auto makeExecutorTestHelper() -> ExecutorTestHelper<inputColumns, outputColumns> {
return ExecutorTestHelper<inputColumns, outputColumns>(*fakedQuery, itemBlockManager);
}

private:
std::vector<std::unique_ptr<ExecutionNode>> _execNodes;

protected:
// available variables
static inline std::unique_ptr<mocks::MockAqlServer> _server;
ResourceMonitor monitor{};
AqlItemBlockManager itemBlockManager{&monitor, SerializationFormat::SHADOWROWS};
std::unique_ptr<arangodb::aql::Query> fakedQuery;
};

/**
* @brief Shortcut handle for parameterized AqlExecutorTestCases with param
*
* @tparam T The Test Parameter used for gtest.
* @tparam enableQueryTrace Enable Aql Profile Trace logging
*/
template <typename T, bool enableQueryTrace = false>
class AqlExecutorTestCaseWithParam : public AqlExecutorTestCase<enableQueryTrace>,
public ::testing::WithParamInterface<T> {};

} // namespace aql
} // namespace tests
} // namespace arangodb
#endif
44 changes: 21 additions & 23 deletions tests/Aql/CalculationExecutorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#include "gtest/gtest.h"

#include "Aql/AqlCall.h"
#include "AqlExecutorTestCase.h"
#include "AqlItemBlockHelper.h"
#include "ExecutorTestHelper.h"
#include "RowFetcherHelper.h"

#include "Aql/AqlItemBlock.h"
Expand Down Expand Up @@ -129,12 +129,11 @@ INSTANTIATE_TEST_CASE_P(CalculationExecutor, CalculationExecutorTest,
splitStep<1>, splitStep<2>));

TEST_P(CalculationExecutorTest, reference_empty_input) {
// auto infos = buildInfos();
AqlCall call{};
ExecutionStats stats{};

ExecutorTestHelper<2, 2>(*fakedQuery)
.setExecBlock<CalculationExecutor<CalculationType::Reference>>(std::move(infos))
makeExecutorTestHelper<2, 2>()
.addConsumer<CalculationExecutor<CalculationType::Reference>>(std::move(infos))
.setInputValue({})
.setInputSplitType(getSplit())
.setCall(call)
Expand All @@ -149,8 +148,8 @@ TEST_P(CalculationExecutorTest, reference_some_input) {
AqlCall call{};
ExecutionStats stats{};

ExecutorTestHelper<2, 2>(*fakedQuery)
.setExecBlock<CalculationExecutor<CalculationType::Reference>>(std::move(infos))
makeExecutorTestHelper<2, 2>()
.addConsumer<CalculationExecutor<CalculationType::Reference>>(std::move(infos))
.setInputValue(MatrixBuilder<2>{
RowBuilder<2>{0, NoneEntry{}}, RowBuilder<2>{1, NoneEntry{}},
RowBuilder<2>{R"("a")", NoneEntry{}}, RowBuilder<2>{2, NoneEntry{}},
Expand All @@ -174,8 +173,8 @@ TEST_P(CalculationExecutorTest, referece_some_input_skip) {
call.offset = 4;
ExecutionStats stats{};

ExecutorTestHelper<2, 2>(*fakedQuery)
.setExecBlock<CalculationExecutor<CalculationType::Reference>>(std::move(infos))
makeExecutorTestHelper<2, 2>()
.addConsumer<CalculationExecutor<CalculationType::Reference>>(std::move(infos))
.setInputValue(MatrixBuilder<2>{
RowBuilder<2>{0, NoneEntry{}}, RowBuilder<2>{1, NoneEntry{}},
RowBuilder<2>{R"("a")", NoneEntry{}}, RowBuilder<2>{2, NoneEntry{}},
Expand All @@ -196,8 +195,8 @@ TEST_P(CalculationExecutorTest, reference_some_input_limit) {
call.hardLimit = 4;
ExecutionStats stats{};

ExecutorTestHelper<2, 2>(*fakedQuery)
.setExecBlock<CalculationExecutor<CalculationType::Reference>>(std::move(infos))
makeExecutorTestHelper<2, 2>()
.addConsumer<CalculationExecutor<CalculationType::Reference>>(std::move(infos))
.setInputValue(MatrixBuilder<2>{
RowBuilder<2>{0, NoneEntry{}}, RowBuilder<2>{1, NoneEntry{}},
RowBuilder<2>{R"("a")", NoneEntry{}}, RowBuilder<2>{2, NoneEntry{}},
Expand All @@ -220,8 +219,8 @@ TEST_P(CalculationExecutorTest, reference_some_input_limit_fullcount) {
call.fullCount = true;
ExecutionStats stats{};

ExecutorTestHelper<2, 2>(*fakedQuery)
.setExecBlock<CalculationExecutor<CalculationType::Reference>>(std::move(infos))
makeExecutorTestHelper<2, 2>()
.addConsumer<CalculationExecutor<CalculationType::Reference>>(std::move(infos))
.setInputValue(MatrixBuilder<2>{
RowBuilder<2>{0, NoneEntry{}}, RowBuilder<2>{1, NoneEntry{}},
RowBuilder<2>{R"("a")", NoneEntry{}}, RowBuilder<2>{2, NoneEntry{}},
Expand All @@ -242,8 +241,8 @@ TEST_P(CalculationExecutorTest, condition_some_input) {
AqlCall call{};
ExecutionStats stats{};

ExecutorTestHelper<2, 2>(*fakedQuery)
.setExecBlock<CalculationExecutor<CalculationType::Condition>>(std::move(infos))
makeExecutorTestHelper<2, 2>()
.addConsumer<CalculationExecutor<CalculationType::Condition>>(std::move(infos))
.setInputValue(MatrixBuilder<2>{
RowBuilder<2>{0, NoneEntry{}}, RowBuilder<2>{1, NoneEntry{}},
RowBuilder<2>{R"("a")", NoneEntry{}}, RowBuilder<2>{2, NoneEntry{}},
Expand All @@ -267,8 +266,8 @@ TEST_P(CalculationExecutorTest, condition_some_input_skip) {
call.offset = 4;
ExecutionStats stats{};

ExecutorTestHelper<2, 2>(*fakedQuery)
.setExecBlock<CalculationExecutor<CalculationType::Condition>>(std::move(infos))
makeExecutorTestHelper<2, 2>()
.addConsumer<CalculationExecutor<CalculationType::Condition>>(std::move(infos))
.setInputValue(MatrixBuilder<2>{
RowBuilder<2>{0, NoneEntry{}}, RowBuilder<2>{1, NoneEntry{}},
RowBuilder<2>{R"("a")", NoneEntry{}}, RowBuilder<2>{2, NoneEntry{}},
Expand All @@ -289,8 +288,8 @@ TEST_P(CalculationExecutorTest, condition_some_input_limit) {
call.hardLimit = 4;
ExecutionStats stats{};

ExecutorTestHelper<2, 2>(*fakedQuery)
.setExecBlock<CalculationExecutor<CalculationType::Condition>>(std::move(infos))
makeExecutorTestHelper<2, 2>()
.addConsumer<CalculationExecutor<CalculationType::Condition>>(std::move(infos))
.setInputValue(MatrixBuilder<2>{
RowBuilder<2>{0, NoneEntry{}}, RowBuilder<2>{1, NoneEntry{}},
RowBuilder<2>{R"("a")", NoneEntry{}}, RowBuilder<2>{2, NoneEntry{}},
Expand All @@ -313,8 +312,8 @@ TEST_P(CalculationExecutorTest, condition_some_input_limit_fullcount) {
call.fullCount = true;
ExecutionStats stats{};

ExecutorTestHelper<2, 2>(*fakedQuery)
.setExecBlock<CalculationExecutor<CalculationType::Condition>>(std::move(infos))
makeExecutorTestHelper<2, 2>()
.addConsumer<CalculationExecutor<CalculationType::Condition>>(std::move(infos))
.setInputValue(MatrixBuilder<2>{
RowBuilder<2>{0, NoneEntry{}}, RowBuilder<2>{1, NoneEntry{}},
RowBuilder<2>{R"("a")", NoneEntry{}}, RowBuilder<2>{2, NoneEntry{}},
Expand All @@ -333,12 +332,11 @@ TEST_P(CalculationExecutorTest, condition_some_input_limit_fullcount) {

// Could be fixed and enabled if one enabled the V8 engine
TEST_P(CalculationExecutorTest, DISABLED_v8condition_some_input) {
// auto infos = buildInfos();
AqlCall call{};
ExecutionStats stats{};

ExecutorTestHelper<2, 2>(*fakedQuery)
.setExecBlock<CalculationExecutor<CalculationType::V8Condition>>(std::move(infos))
makeExecutorTestHelper<2, 2>()
.addConsumer<CalculationExecutor<CalculationType::V8Condition>>(std::move(infos))
.setInputValue(MatrixBuilder<2>{
RowBuilder<2>{0, NoneEntry{}}, RowBuilder<2>{1, NoneEntry{}},
RowBuilder<2>{R"("a")", NoneEntry{}}, RowBuilder<2>{2, NoneEntry{}},
Expand Down
Loading
0