diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a8d938a..25f48aa 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -163,9 +163,7 @@ set_tests_properties(test_kernel_shell PROPERTIES ENVIRONMENT "JUPYTER_PATH=${CMAKE_CURRENT_BINARY_DIR}") -# TODO: enable this again when the ipc client -# is implemented -if (FALSE) +if (UNIX) # Test_kernel_ipc # =============== @@ -183,10 +181,12 @@ if (FALSE) # =============== set(TEST_CLIENT_IPC_SOURCES + xipc_client.cpp + xipc_client.hpp client_ipc.cpp) add_executable(test_client_ipc ${TEST_CLIENT_IPC_SOURCES}) target_link_libraries(test_client_ipc PRIVATE ${xeus-zmq_TARGET} Threads::Threads) target_compile_features(test_client_ipc PRIVATE cxx_std_17) -endif (FALSE) +endif (UNIX) diff --git a/test/client_ipc.cpp b/test/client_ipc.cpp index 763e0b0..4f74dfb 100644 --- a/test/client_ipc.cpp +++ b/test/client_ipc.cpp @@ -6,34 +6,35 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -// TODO: this client should be reimplemented with -// the new client framework. Notice that it was not -// tested in the CI but was here for trying to reproduce -// some issue with IPC. - -/*#include +#include #include "zmq_addon.hpp" #include "nlohmann/json.hpp" #include "xeus/xguid.hpp" #include "xeus/xmessage.hpp" -#include "xeus-zmq/xauthentication.hpp" -#include "xeus-zmq/xmiddleware.hpp" -#include "xeus-zmq/xzmq_serializer.hpp" +#include "xeus/xkernel_configuration.hpp" +#include "xeus-zmq/xzmq_context.hpp" +#include "xipc_client.hpp" namespace nl = nlohmann; int main(int, char**) { - zmq::context_t context; - zmq::socket_t cli(context, zmq::socket_type::dealer); - xeus::xguid socket_id = xeus::new_xguid(); - //cli.set(ZMQ_IDENTITY, socket_id.c_str(), socket_id.size()); - cli.set(zmq::sockopt::linger, xeus::get_socket_linger()); - cli.connect(xeus::get_end_point("ipc", "localhost", "shell")); + auto context_ptr = xeus::make_zmq_context(); + xeus::xconfiguration config; + config.m_transport = "ipc"; + config.m_ip = "localhost"; + config.m_control_port = "control"; + config.m_shell_port = "shell"; + config.m_stdin_port = "stdin"; + config.m_iopub_port = "iopub"; + config.m_hb_port = "heartbeat"; + config.m_signature_scheme = "none"; + config.m_key = ""; - auto auth = xeus::make_xauthentication("none", ""); + xeus::xipc_client ipc_client(*context_ptr, config); + xeus::xguid socket_id = xeus::new_xguid(); nl::json header = xeus::make_header("execute_request", "tester", "DAEDZFAEDE12"); std::string code = "std::cout << \"this is a test\" << std::endl;"; nl::json req = { @@ -48,15 +49,19 @@ int main(int, char**) nl::json::object(), xeus::buffer_sequence() ); - auto wire_msg = xeus::xzmq_serializer::serialize(std::move(msg), *auth); - wire_msg.send(cli); - zmq::multipart_t resp_msg; - resp_msg.recv(cli); + ipc_client.send_on_shell(std::move(msg)); - auto resp = xeus::xzmq_serializer::deserialize(resp_msg, *auth); - std::cout << resp.content().dump(4) << std::endl; + auto response = ipc_client.check_shell_answer(); + if (response.has_value()) + { + std::cout << response->content().dump(4) << std::endl; + } + else + { + std::cout << "No response received" << std::endl; + } return 0; -}*/ +} diff --git a/test/xipc_client.cpp b/test/xipc_client.cpp new file mode 100644 index 0000000..6521a9a --- /dev/null +++ b/test/xipc_client.cpp @@ -0,0 +1,28 @@ +/*************************************************************************** +* Copyright (c) 2016, Johan Mabille and Sylvain Corlay * +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#include "xipc_client.hpp" + +namespace xeus +{ + + xipc_client::xipc_client(xcontext& context, const xconfiguration& config) + : p_client(make_xclient_zmq(context, config)) + { + } + + void xipc_client::send_on_shell(xmessage msg) + { + p_client->send_on_shell(std::move(msg)); + } + + std::optional xipc_client::check_shell_answer() + { + return p_client->check_shell_answer(); + } +} \ No newline at end of file diff --git a/test/xipc_client.hpp b/test/xipc_client.hpp new file mode 100644 index 0000000..62779f0 --- /dev/null +++ b/test/xipc_client.hpp @@ -0,0 +1,31 @@ +/*************************************************************************** +* Copyright (c) 2016, Johan Mabille and Sylvain Corlay * +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#ifndef XEUS_IPC_CLIENT_HPP +#define XEUS_IPC_CLIENT_HPP + +#include "xeus-zmq/xclient_zmq.hpp" + +namespace xeus +{ + class xipc_client + { + public: + using client_ptr = std::unique_ptr; + + xipc_client(xcontext& context, const xconfiguration& config); + + void send_on_shell(xmessage msg); + std::optional check_shell_answer(); + + private: + client_ptr p_client; + }; +} + +#endif