Fix shutdown call (#395)
* Fix shutdown not called * Add ssl server tests
This commit is contained in:
parent
8059a3e653
commit
22bd60c613
@ -246,11 +246,7 @@ class Session final : public std::enable_shared_from_this<Session<TSession, TSes
|
|||||||
Session(Session &&) = delete;
|
Session(Session &&) = delete;
|
||||||
Session &operator=(const Session &) = delete;
|
Session &operator=(const Session &) = delete;
|
||||||
Session &operator=(Session &&) = delete;
|
Session &operator=(Session &&) = delete;
|
||||||
~Session() {
|
~Session() = default;
|
||||||
if (IsConnected()) {
|
|
||||||
spdlog::error("Session: Destructor called while execution is active");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Start() {
|
bool Start() {
|
||||||
if (execution_active_) {
|
if (execution_active_) {
|
||||||
@ -400,7 +396,6 @@ class Session final : public std::enable_shared_from_this<Session<TSession, TSes
|
|||||||
if (ec == boost::asio::error::operation_aborted) {
|
if (ec == boost::asio::error::operation_aborted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
execution_active_ = false;
|
|
||||||
|
|
||||||
if (ec == boost::asio::error::eof) {
|
if (ec == boost::asio::error::eof) {
|
||||||
spdlog::info("Session closed by peer");
|
spdlog::info("Session closed by peer");
|
||||||
|
@ -22,6 +22,7 @@ add_custom_target(memgraph__e2e__${TARGET_PREFIX}__${FILE_NAME} ALL
|
|||||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE_NAME})
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE_NAME})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
add_subdirectory(server)
|
||||||
add_subdirectory(replication)
|
add_subdirectory(replication)
|
||||||
add_subdirectory(memory)
|
add_subdirectory(memory)
|
||||||
add_subdirectory(triggers)
|
add_subdirectory(triggers)
|
||||||
@ -31,6 +32,8 @@ add_subdirectory(temporal_types)
|
|||||||
add_subdirectory(write_procedures)
|
add_subdirectory(write_procedures)
|
||||||
add_subdirectory(magic_functions)
|
add_subdirectory(magic_functions)
|
||||||
add_subdirectory(module_file_manager)
|
add_subdirectory(module_file_manager)
|
||||||
add_subdirectory(websocket)
|
add_subdirectory(monitoring_server)
|
||||||
|
|
||||||
copy_e2e_python_files(pytest_runner pytest_runner.sh "")
|
copy_e2e_python_files(pytest_runner pytest_runner.sh "")
|
||||||
|
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/memgraph-selfsigned.crt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/memgraph-selfsigned.key DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
8
tests/e2e/monitoring_server/CMakeLists.txt
Normal file
8
tests/e2e/monitoring_server/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
find_package(gflags REQUIRED)
|
||||||
|
find_package(Boost REQUIRED)
|
||||||
|
|
||||||
|
add_executable(memgraph__e2e__monitoring_server monitoring.cpp)
|
||||||
|
target_link_libraries(memgraph__e2e__monitoring_server mgclient mg-utils json gflags Boost::headers)
|
||||||
|
|
||||||
|
add_executable(memgraph__e2e__monitoring_server_ssl monitoring_ssl.cpp)
|
||||||
|
target_link_libraries(memgraph__e2e__monitoring_server_ssl mgclient mg-utils json gflags Boost::headers)
|
@ -1,15 +1,15 @@
|
|||||||
cert_file: &cert_file "$PROJECT_DIR/tests/e2e/websocket/memgraph-selfsigned.crt"
|
cert_file: &cert_file "$PROJECT_DIR/tests/e2e/memgraph-selfsigned.crt"
|
||||||
key_file: &key_file "$PROJECT_DIR/tests/e2e/websocket/memgraph-selfsigned.key"
|
key_file: &key_file "$PROJECT_DIR/tests/e2e/memgraph-selfsigned.key"
|
||||||
bolt_port: &bolt_port "7687"
|
bolt_port: &bolt_port "7687"
|
||||||
monitoring_port: &monitoring_port "7444"
|
monitoring_port: &monitoring_port "7444"
|
||||||
template_cluster: &template_cluster
|
template_cluster: &template_cluster
|
||||||
cluster:
|
cluster:
|
||||||
websocket:
|
monitoring:
|
||||||
args: ["--bolt-port=7687", "--log-level=TRACE", "--"]
|
args: ["--bolt-port=7687", "--log-level=TRACE", "--"]
|
||||||
log_file: "websocket-e2e.log"
|
log_file: "monitoring-websocket-e2e.log"
|
||||||
template_cluster_ssl: &template_cluster_ssl
|
template_cluster_ssl: &template_cluster_ssl
|
||||||
cluster:
|
cluster:
|
||||||
websocket:
|
monitoring:
|
||||||
args:
|
args:
|
||||||
[
|
[
|
||||||
"--bolt-port",
|
"--bolt-port",
|
||||||
@ -23,16 +23,15 @@ template_cluster_ssl: &template_cluster_ssl
|
|||||||
*key_file,
|
*key_file,
|
||||||
"--",
|
"--",
|
||||||
]
|
]
|
||||||
log_file: "websocket-ssl-e2e.log"
|
log_file: "monitoring-websocket-ssl-e2e.log"
|
||||||
ssl: true
|
ssl: true
|
||||||
|
|
||||||
workloads:
|
workloads:
|
||||||
- name: "Websocket"
|
- name: "Monitoring server using WebSocket"
|
||||||
binary: "tests/e2e/websocket/memgraph__e2e__websocket"
|
binary: "tests/e2e/monitoring_server/memgraph__e2e__monitoring_server"
|
||||||
args: ["--bolt-port", *bolt_port, "--monitoring-port", *monitoring_port]
|
args: ["--bolt-port", *bolt_port, "--monitoring-port", *monitoring_port]
|
||||||
<<: *template_cluster
|
<<: *template_cluster
|
||||||
- name: "Websocket SSL"
|
- name: "Monitoring server using WebSocket SSL"
|
||||||
binary: "tests/e2e/websocket/memgraph__e2e__websocket_ssl"
|
binary: "tests/e2e/monitoring_server/memgraph__e2e__monitoring_server_ssl"
|
||||||
args: ["--bolt-port", *bolt_port, "--monitoring-port", *monitoring_port]
|
args: ["--bolt-port", *bolt_port, "--monitoring-port", *monitoring_port]
|
||||||
<<: *template_cluster_ssl
|
<<: *template_cluster_ssl
|
||||||
|
|
8
tests/e2e/server/CMakeLists.txt
Normal file
8
tests/e2e/server/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
find_package(gflags REQUIRED)
|
||||||
|
find_package(Boost REQUIRED)
|
||||||
|
|
||||||
|
add_executable(memgraph__e2e__server_connection server_connection.cpp)
|
||||||
|
target_link_libraries(memgraph__e2e__server_connection mgclient mg-utils gflags)
|
||||||
|
|
||||||
|
add_executable(memgraph__e2e__server_ssl_connection server_ssl_connection.cpp)
|
||||||
|
target_link_libraries(memgraph__e2e__server_ssl_connection mgclient mg-utils gflags)
|
60
tests/e2e/server/common.hpp
Normal file
60
tests/e2e/server/common.hpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
// 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 <chrono>
|
||||||
|
#include <functional>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <boost/asio/io_context.hpp>
|
||||||
|
#include <boost/asio/steady_timer.hpp>
|
||||||
|
#include <boost/system/detail/error_code.hpp>
|
||||||
|
#include <mgclient.hpp>
|
||||||
|
|
||||||
|
#include "utils/logging.hpp"
|
||||||
|
|
||||||
|
inline void OnTimeoutExpiration(const boost::system::error_code &ec) {
|
||||||
|
// Timer was not cancelled, take necessary action.
|
||||||
|
MG_ASSERT(!!ec, "Connection timeout");
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void EstablishConnection(const uint16_t bolt_port, const bool use_ssl) {
|
||||||
|
spdlog::info("Testing successfull connection from one client");
|
||||||
|
mg::Client::Init();
|
||||||
|
|
||||||
|
boost::asio::io_context ioc;
|
||||||
|
boost::asio::steady_timer timer(ioc, std::chrono::seconds(5));
|
||||||
|
timer.async_wait(std::bind_front(&OnTimeoutExpiration));
|
||||||
|
std::jthread bg_thread([&ioc]() { ioc.run(); });
|
||||||
|
|
||||||
|
auto client = mg::Client::Connect({.host = "127.0.0.1", .port = bolt_port, .use_ssl = use_ssl});
|
||||||
|
MG_ASSERT(client, "Failed to connect!");
|
||||||
|
timer.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void EstablishMultipleConnections(const uint16_t bolt_port, const bool use_ssl) {
|
||||||
|
spdlog::info("Testing successfull connection from multiple clients");
|
||||||
|
mg::Client::Init();
|
||||||
|
|
||||||
|
boost::asio::io_context ioc;
|
||||||
|
boost::asio::steady_timer timer(ioc, std::chrono::seconds(5));
|
||||||
|
timer.async_wait(std::bind_front(&OnTimeoutExpiration));
|
||||||
|
std::jthread bg_thread([&ioc]() { ioc.run(); });
|
||||||
|
|
||||||
|
auto client1 = mg::Client::Connect({.host = "127.0.0.1", .port = bolt_port, .use_ssl = use_ssl});
|
||||||
|
auto client2 = mg::Client::Connect({.host = "127.0.0.1", .port = bolt_port, .use_ssl = use_ssl});
|
||||||
|
auto client3 = mg::Client::Connect({.host = "127.0.0.1", .port = bolt_port, .use_ssl = use_ssl});
|
||||||
|
|
||||||
|
MG_ASSERT(client1, "Failed to connect!");
|
||||||
|
MG_ASSERT(client2, "Failed to connect!");
|
||||||
|
MG_ASSERT(client3, "Failed to connect!");
|
||||||
|
timer.cancel();
|
||||||
|
}
|
56
tests/e2e/server/server_connection.cpp
Normal file
56
tests/e2e/server/server_connection.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// 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 <unistd.h>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
#include <gflags/gflags.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <boost/asio/io_context.hpp>
|
||||||
|
#include <boost/asio/steady_timer.hpp>
|
||||||
|
#include <boost/system/detail/error_code.hpp>
|
||||||
|
#include <mgclient.hpp>
|
||||||
|
|
||||||
|
#include "common.hpp"
|
||||||
|
#include "utils/logging.hpp"
|
||||||
|
|
||||||
|
DEFINE_uint64(bolt_port, 7687, "Bolt port");
|
||||||
|
|
||||||
|
void EstablishSSLConnectionToNonSSLServer(const auto bolt_port) {
|
||||||
|
spdlog::info("Testing that connection fails when connecting to non SSL server while using SSL");
|
||||||
|
mg::Client::Init();
|
||||||
|
|
||||||
|
boost::asio::io_context ioc;
|
||||||
|
boost::asio::steady_timer timer(ioc, std::chrono::seconds(5));
|
||||||
|
timer.async_wait(std::bind_front(&OnTimeoutExpiration));
|
||||||
|
std::jthread bg_thread([&ioc]() { ioc.run(); });
|
||||||
|
|
||||||
|
auto client = mg::Client::Connect({.host = "127.0.0.1", .port = bolt_port, .use_ssl = true});
|
||||||
|
|
||||||
|
MG_ASSERT(client == nullptr, "Connection not refused when connecting with SSL turned on to a non SSL server!");
|
||||||
|
timer.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
google::SetUsageMessage("Memgraph E2E server connection!");
|
||||||
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||||
|
MG_ASSERT(FLAGS_bolt_port != 0);
|
||||||
|
memgraph::logging::RedirectToStderr();
|
||||||
|
|
||||||
|
const auto bolt_port = static_cast<uint16_t>(FLAGS_bolt_port);
|
||||||
|
|
||||||
|
EstablishConnection(bolt_port, false);
|
||||||
|
EstablishMultipleConnections(bolt_port, false);
|
||||||
|
EstablishSSLConnectionToNonSSLServer(bolt_port);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
57
tests/e2e/server/server_ssl_connection.cpp
Normal file
57
tests/e2e/server/server_ssl_connection.cpp
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// 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 <unistd.h>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
#include <gflags/gflags.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <boost/asio/io_context.hpp>
|
||||||
|
#include <boost/asio/steady_timer.hpp>
|
||||||
|
#include <boost/system/detail/error_code.hpp>
|
||||||
|
#include <mgclient.hpp>
|
||||||
|
|
||||||
|
#include "common.hpp"
|
||||||
|
#include "utils/logging.hpp"
|
||||||
|
|
||||||
|
DEFINE_uint64(bolt_port, 7687, "Bolt port");
|
||||||
|
|
||||||
|
void EstablishNonSSLConnectionToSSLServer(const auto bolt_port) {
|
||||||
|
spdlog::info("Testing that connection fails when connecting to SSL server without using SSL");
|
||||||
|
mg::Client::Init();
|
||||||
|
|
||||||
|
boost::asio::io_context ioc;
|
||||||
|
boost::asio::steady_timer timer(ioc, std::chrono::seconds(5));
|
||||||
|
timer.async_wait(std::bind_front(&OnTimeoutExpiration));
|
||||||
|
std::jthread bg_thread([&ioc]() { ioc.run(); });
|
||||||
|
|
||||||
|
auto client = mg::Client::Connect({.host = "127.0.0.1", .port = bolt_port, .use_ssl = false});
|
||||||
|
|
||||||
|
MG_ASSERT(client == nullptr, "Connection not refused when conneting without SSL turned on to a SSL server!");
|
||||||
|
timer.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
google::SetUsageMessage("Memgraph E2E server SSL connection!");
|
||||||
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||||
|
MG_ASSERT(FLAGS_bolt_port != 0);
|
||||||
|
memgraph::logging::RedirectToStderr();
|
||||||
|
|
||||||
|
const auto bolt_port = static_cast<uint16_t>(FLAGS_bolt_port);
|
||||||
|
|
||||||
|
EstablishConnection(bolt_port, true);
|
||||||
|
EstablishMultipleConnections(bolt_port, true);
|
||||||
|
EstablishNonSSLConnectionToSSLServer(bolt_port);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
34
tests/e2e/server/workloads.yaml
Normal file
34
tests/e2e/server/workloads.yaml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
cert_file: &cert_file "$PROJECT_DIR/tests/e2e/memgraph-selfsigned.crt"
|
||||||
|
key_file: &key_file "$PROJECT_DIR/tests/e2e/memgraph-selfsigned.key"
|
||||||
|
bolt_port: &bolt_port "7687"
|
||||||
|
template_cluster: &template_cluster
|
||||||
|
cluster:
|
||||||
|
server:
|
||||||
|
args: ["--bolt-port=7687", "--log-level=TRACE", "--"]
|
||||||
|
log_file: "server-connection-e2e.log"
|
||||||
|
template_cluster_ssl: &template_cluster_ssl
|
||||||
|
cluster:
|
||||||
|
server:
|
||||||
|
args:
|
||||||
|
[
|
||||||
|
"--bolt-port",
|
||||||
|
*bolt_port,
|
||||||
|
"--log-level=TRACE",
|
||||||
|
"--bolt-cert-file",
|
||||||
|
*cert_file,
|
||||||
|
"--bolt-key-file",
|
||||||
|
*key_file,
|
||||||
|
"--",
|
||||||
|
]
|
||||||
|
log_file: "server-connection-ssl-e2e.log"
|
||||||
|
ssl: true
|
||||||
|
|
||||||
|
workloads:
|
||||||
|
- name: "Server connection"
|
||||||
|
binary: "tests/e2e/server/memgraph__e2e__server_connection"
|
||||||
|
args: ["--bolt-port", *bolt_port]
|
||||||
|
<<: *template_cluster
|
||||||
|
- name: "Server SSL connection"
|
||||||
|
binary: "tests/e2e/server/memgraph__e2e__server_ssl_connection"
|
||||||
|
args: ["--bolt-port", *bolt_port]
|
||||||
|
<<: *template_cluster_ssl
|
@ -1,10 +0,0 @@
|
|||||||
find_package(gflags REQUIRED)
|
|
||||||
find_package(Boost REQUIRED)
|
|
||||||
|
|
||||||
add_executable(memgraph__e2e__websocket websocket.cpp)
|
|
||||||
target_link_libraries(memgraph__e2e__websocket mgclient mg-utils json gflags Boost::headers)
|
|
||||||
|
|
||||||
add_executable(memgraph__e2e__websocket_ssl websocket_ssl.cpp)
|
|
||||||
target_link_libraries(memgraph__e2e__websocket_ssl mgclient mg-utils json gflags Boost::headers)
|
|
||||||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/memgraph-selfsigned.crt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
|
||||||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/memgraph-selfsigned.key DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
|
Loading…
Reference in New Issue
Block a user