From 1cc07210f3a07df8f5f899444f7889ca58a2da05 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Fri, 14 Jun 2024 12:44:05 +0530 Subject: [PATCH] Use connect and stop_channel functions --- test/test_debugger.cpp | 8 ++++ test/xeus_client.cpp | 86 ++++-------------------------------------- test/xeus_client.hpp | 11 +++--- 3 files changed, 21 insertions(+), 84 deletions(-) diff --git a/test/test_debugger.cpp b/test/test_debugger.cpp index e5112f5a..971413ad 100644 --- a/test/test_debugger.cpp +++ b/test/test_debugger.cpp @@ -400,6 +400,7 @@ class debugger_client bool test_rich_inspect_variables(); bool test_variables(); bool test_copy_to_globals(); + void start(); void shutdown(); private: @@ -965,8 +966,14 @@ bool debugger_client::test_copy_to_globals() return global_var["value"] == local_var["value"] && global_var["type"] == local_var["type"]; } +void debugger_client::start() +{ + m_client.start(); +} + void debugger_client::shutdown() { + m_client.stop_channels(); m_client.send_on_control("shutdown_request", make_shutdown_request()); m_client.receive_on_control(); } @@ -1147,6 +1154,7 @@ TEST_SUITE("debugger") xeus::xcontext context; { debugger_client deb(context, KERNEL_JSON, "debugger_init.log"); + deb.start(); bool res = deb.test_init(); deb.shutdown(); std::this_thread::sleep_for(2s); diff --git a/test/xeus_client.cpp b/test/xeus_client.cpp index 3eb43f3b..db85ba75 100644 --- a/test/xeus_client.cpp +++ b/test/xeus_client.cpp @@ -34,9 +34,8 @@ xeus_logger_client::xeus_logger_client(xeus::xcontext& context, std::ofstream out(m_file_name); out << "STARTING CLIENT" << std::endl; - // Register listeners for shell and kernel status - register_shell_listener(); - register_kernel_status_listener(); + // TODO + p_client->connect(); } xeus_logger_client::~xeus_logger_client() @@ -128,12 +127,13 @@ std::size_t xeus_logger_client::iopub_queue_size() const nl::json xeus_logger_client::pop_iopub_message() { - std::optional msg_opt = p_client->pop_iopub_message(); + optional msg_opt = p_client->pop_iopub_message(); nl::json result = nl::json::object(); if (msg_opt.has_value()) { - xeus::xmessage msg = std::move(*msg_opt); + xeus::xpub_xmessage msg = std::move(*msg_opt); + result["topic"] = msg.topic(); result["header"] = msg.header(); result["parent_header"] = msg.parent_header(); result["metadata"] = msg.metadata(); @@ -143,86 +143,14 @@ nl::json xeus_logger_client::pop_iopub_message() return result; } -nl::json xeus_logger_client::wait_for_debug_event(const std::string& event) -{ - bool event_found = false; - nl::json msg; - while(!event_found) - { - std::size_t s = iopub_queue_size(); - if(s != 0) - { - msg = pop_iopub_message(); - if(msg["topic"] == "debug_event" && msg["content"]["event"] == event) - { - event_found = true; - } - } - else - { - std::unique_lock lk(m_notify_mutex); - if(iopub_queue_size()) - { - continue; - } - m_notify_cond.wait(lk); - } - } - return msg; -} - void xeus_logger_client::start() { p_client->start(); } -void xeus_logger_client::register_shell_listener() -{ - p_client->register_shell_listener([this](xeus::xmessage msg) { - handle_shell_message(std::move(msg)); - }); -} - -void xeus_logger_client::register_kernel_status_listener() -{ - p_client->register_kernel_status_listener([this](bool status) { - handle_kernel_status_message(status); - }); -} - -void xeus_logger_client::handle_shell_message(xeus::xmessage msg) +void xeus_logger_client::stop_channels() { - nl::json json_msg; - json_msg["header"] = msg.header(); - json_msg["parent_header"] = msg.parent_header(); - json_msg["metadata"] = msg.metadata(); - json_msg["content"] = msg.content(); - - log_message(json_msg); - - std::string topic = json_msg["topic"]; - std::size_t topic_size = topic.size(); - if (topic.substr(topic_size - 8, topic_size) == "shutdown") - { - std::cout << "Received shutdown, exiting" << std::endl; - // TODO - } -} - -void xeus_logger_client::handle_kernel_status_message(bool status) -{ - nl::json msg; - if (status) - { - // TODO - // msg["topic"] = "Kernel is dead"; - } - else - { - // TODO - // msg["topic"] = "Kernel is alive"; - } - log_message(msg); + p_client->stop_channels(); } void xeus_logger_client::log_message(nl::json msg) diff --git a/test/xeus_client.hpp b/test/xeus_client.hpp index 99f1eab5..2b3c444d 100644 --- a/test/xeus_client.hpp +++ b/test/xeus_client.hpp @@ -45,17 +45,18 @@ class xeus_logger_client std::size_t iopub_queue_size() const; nl::json pop_iopub_message(); - nl::json wait_for_debug_event(const std::string& event); + // nl::json wait_for_debug_event(const std::string& event); void start(); + void stop_channels(); void log_message(nl::json msg); private: - void register_shell_listener(); - void register_kernel_status_listener(); + // void register_shell_listener(); + // void register_kernel_status_listener(); - void handle_shell_message(xeus::xmessage msg); - void handle_kernel_status_message(bool status); + // void handle_shell_message(xeus::xmessage msg); + // void handle_kernel_status_message(bool status); std::string m_user_name; std::string m_file_name;