From b782271be87a04173ebe7c724358ba107b15dd9a Mon Sep 17 00:00:00 2001 From: Jeremy B <97525434+42jeremy@users.noreply.github.com> Date: Thu, 28 Apr 2022 20:28:44 +0200 Subject: [PATCH] Fix shared module loading * Moving function add_query_module from CMakeLists from tests/e2e/magic_functions to tests/e2e * Adding failing test copying behavior when loading c module (.so) into memgraph. * Fixing issue where NO_ERROR status returned MgpTransAddFixedResult was converted to false * Removing unnecessary transformation * removing incorrect parameterization of test * re-adding parametrized transformation --- src/query/procedure/module.cpp | 4 +-- tests/e2e/CMakeLists.txt | 8 ++++++ tests/e2e/magic_functions/CMakeLists.txt | 7 ----- tests/e2e/streams/kafka_streams_tests.py | 28 +++++++++++++------ .../streams/transformations/CMakeLists.txt | 1 + .../transformations/c_transformations.cpp | 22 +++++++++++++++ 6 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 tests/e2e/streams/transformations/c_transformations.cpp diff --git a/src/query/procedure/module.cpp b/src/query/procedure/module.cpp index 357dfba31..427010803 100644 --- a/src/query/procedure/module.cpp +++ b/src/query/procedure/module.cpp @@ -832,8 +832,8 @@ bool SharedLibraryModule::Load(const std::filesystem::path &file_path) { return with_error(error); } for (auto &trans : module_def->transformations) { - const bool was_result_added = MgpTransAddFixedResult(&trans.second); - if (!was_result_added) { + const bool success = MGP_ERROR_NO_ERROR == MgpTransAddFixedResult(&trans.second); + if (!success) { const auto error = fmt::format("Unable to add result to transformation in module {}; add result failed", file_path); return with_error(error); diff --git a/tests/e2e/CMakeLists.txt b/tests/e2e/CMakeLists.txt index 4a53a0836..c8c0913f5 100644 --- a/tests/e2e/CMakeLists.txt +++ b/tests/e2e/CMakeLists.txt @@ -1,3 +1,11 @@ +# Set up C++ functions for e2e tests +function(add_query_module target_name src) + add_library(${target_name} SHARED ${src}) + SET_TARGET_PROPERTIES(${target_name} PROPERTIES PREFIX "") + target_include_directories(${target_name} PRIVATE ${CMAKE_SOURCE_DIR}/include) +endfunction() + + function(copy_e2e_python_files TARGET_PREFIX FILE_NAME) add_custom_target(memgraph__e2e__${TARGET_PREFIX}__${FILE_NAME} ALL COMMAND ${CMAKE_COMMAND} -E copy diff --git a/tests/e2e/magic_functions/CMakeLists.txt b/tests/e2e/magic_functions/CMakeLists.txt index fb4986724..3ab627e22 100644 --- a/tests/e2e/magic_functions/CMakeLists.txt +++ b/tests/e2e/magic_functions/CMakeLists.txt @@ -1,10 +1,3 @@ -# Set up C++ functions for e2e tests -function(add_query_module target_name src) - add_library(${target_name} SHARED ${src}) - SET_TARGET_PROPERTIES(${target_name} PROPERTIES PREFIX "") - target_include_directories(${target_name} PRIVATE ${CMAKE_SOURCE_DIR}/include) -endfunction() - # Set up Python functions for e2e tests function(copy_magic_functions_e2e_python_files FILE_NAME) copy_e2e_python_files(functions ${FILE_NAME}) diff --git a/tests/e2e/streams/kafka_streams_tests.py b/tests/e2e/streams/kafka_streams_tests.py index 1455fe95d..0d2e14c78 100755 --- a/tests/e2e/streams/kafka_streams_tests.py +++ b/tests/e2e/streams/kafka_streams_tests.py @@ -18,12 +18,14 @@ import time from multiprocessing import Process, Value import common -TRANSFORMATIONS_TO_CHECK = [ +TRANSFORMATIONS_TO_CHECK_C = [ + "empty_transformation"] + +TRANSFORMATIONS_TO_CHECK_PY = [ "kafka_transform.simple", "kafka_transform.with_parameters"] - -@pytest.mark.parametrize("transformation", TRANSFORMATIONS_TO_CHECK) +@pytest.mark.parametrize("transformation", TRANSFORMATIONS_TO_CHECK_PY) def test_simple(kafka_producer, kafka_topics, connection, transformation): assert len(kafka_topics) > 0 cursor = connection.cursor() @@ -44,7 +46,7 @@ def test_simple(kafka_producer, kafka_topics, connection, transformation): cursor, topic, common.SIMPLE_MSG) -@pytest.mark.parametrize("transformation", TRANSFORMATIONS_TO_CHECK) +@pytest.mark.parametrize("transformation", TRANSFORMATIONS_TO_CHECK_PY) def test_separate_consumers( kafka_producer, kafka_topics, @@ -125,7 +127,7 @@ def test_start_from_last_committed_offset( cursor, kafka_topics[0], message) -@pytest.mark.parametrize("transformation", TRANSFORMATIONS_TO_CHECK) +@pytest.mark.parametrize("transformation", TRANSFORMATIONS_TO_CHECK_PY) def test_check_stream( kafka_producer, kafka_topics, @@ -307,7 +309,7 @@ def test_restart_after_error(kafka_producer, kafka_topics, connection): cursor, "MATCH (n:VERTEX { id : 42 }) RETURN n") -@pytest.mark.parametrize("transformation", TRANSFORMATIONS_TO_CHECK) +@pytest.mark.parametrize("transformation", TRANSFORMATIONS_TO_CHECK_PY) def test_bootstrap_server( kafka_producer, kafka_topics, @@ -334,7 +336,7 @@ def test_bootstrap_server( cursor, topic, common.SIMPLE_MSG) -@pytest.mark.parametrize("transformation", TRANSFORMATIONS_TO_CHECK) +@pytest.mark.parametrize("transformation", TRANSFORMATIONS_TO_CHECK_PY) def test_bootstrap_server_empty( kafka_producer, kafka_topics, @@ -352,7 +354,7 @@ def test_bootstrap_server_empty( ) -@pytest.mark.parametrize("transformation", TRANSFORMATIONS_TO_CHECK) +@pytest.mark.parametrize("transformation", TRANSFORMATIONS_TO_CHECK_PY) def test_set_offset(kafka_producer, kafka_topics, connection, transformation): assert len(kafka_topics) > 0 cursor = connection.cursor() @@ -450,6 +452,14 @@ def test_info_procedure(kafka_topics, connection): (local, configs, consumer_group, reducted_credentials, kafka_topics)] common.validate_info(stream_info, expected_stream_info) - +@pytest.mark.parametrize("transformation",TRANSFORMATIONS_TO_CHECK_C) +def test_load_c_transformations(connection, transformation): + cursor = connection.cursor() + query = "CALL mg.transformations() YIELD * WITH name WHERE name STARTS WITH 'c_transformations." + transformation + "' RETURN name" + result = common.execute_and_fetch_all( + cursor, query) + assert len(result) == 1 + assert result[0][0] == "c_transformations." + transformation + if __name__ == "__main__": sys.exit(pytest.main([__file__, "-rA"])) diff --git a/tests/e2e/streams/transformations/CMakeLists.txt b/tests/e2e/streams/transformations/CMakeLists.txt index 8934a3ce7..5ecafd43a 100644 --- a/tests/e2e/streams/transformations/CMakeLists.txt +++ b/tests/e2e/streams/transformations/CMakeLists.txt @@ -1,2 +1,3 @@ copy_streams_e2e_python_files(kafka_transform.py) copy_streams_e2e_python_files(pulsar_transform.py) +add_query_module(c_transformations c_transformations.cpp) diff --git a/tests/e2e/streams/transformations/c_transformations.cpp b/tests/e2e/streams/transformations/c_transformations.cpp new file mode 100644 index 000000000..984a04c61 --- /dev/null +++ b/tests/e2e/streams/transformations/c_transformations.cpp @@ -0,0 +1,22 @@ +// Copyright 2022 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#include "mg_procedure.h" + +extern "C" int mgp_init_module(mgp_module *module, mgp_memory *memory) { + static const auto no_op_cb = [](mgp_messages *msg, mgp_graph *graph, mgp_result *result, mgp_memory *memory) {}; + + if (MGP_ERROR_NO_ERROR != mgp_module_add_transformation(module, "empty_transformation", no_op_cb)) { + return 1; + } + + return 0; +} \ No newline at end of file