Skip to content

Commit

Permalink
Implementing wait_for_debug_event
Browse files Browse the repository at this point in the history
  • Loading branch information
anutosh491 committed Jun 14, 2024
1 parent 1cc0721 commit 05ddd63
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
6 changes: 4 additions & 2 deletions test/test_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "xeus_client.hpp"

#include "xeus-zmq/xzmq_context.hpp"

#include "pybind11/pybind11.h"

#include <stdio.h>
Expand Down Expand Up @@ -1151,9 +1153,9 @@ TEST_SUITE("debugger")
{
start_kernel();
timer t;
xeus::xcontext context;
auto context_ptr = xeus::make_zmq_context();
{
debugger_client deb(context, KERNEL_JSON, "debugger_init.log");
debugger_client deb(*context_ptr, KERNEL_JSON, "debugger_init.log");
deb.start();
bool res = deb.test_init();
deb.shutdown();
Expand Down
32 changes: 30 additions & 2 deletions test/xeus_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ std::size_t xeus_logger_client::iopub_queue_size() const

nl::json xeus_logger_client::pop_iopub_message()
{
optional<xeus::xpub_message> msg_opt = p_client->pop_iopub_message();
std::optional<xeus::xpub_message> msg_opt = p_client->pop_iopub_message();
nl::json result = nl::json::object();

if (msg_opt.has_value())
{
xeus::xpub_xmessage msg = std::move(*msg_opt);
xeus::xpub_message msg = std::move(*msg_opt);
result["topic"] = msg.topic();
result["header"] = msg.header();
result["parent_header"] = msg.parent_header();
Expand All @@ -143,6 +143,34 @@ 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<std::mutex> lk(m_notify_mutex);
if(iopub_queue_size())
{
continue;
}
m_notify_cond.wait(lk);
}
}
return msg;
}

void xeus_logger_client::start()
{
p_client->start();
Expand Down
8 changes: 1 addition & 7 deletions test/xeus_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,13 @@ 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 handle_shell_message(xeus::xmessage msg);
// void handle_kernel_status_message(bool status);

std::string m_user_name;
std::string m_file_name;
std::mutex m_file_mutex;
Expand Down

0 comments on commit 05ddd63

Please sign in to comment.