Skip to content

Commit 6ad6c05

Browse files
committed
applied jupyter-xeus#685 to async pr
1 parent a569228 commit 6ad6c05

2 files changed

Lines changed: 38 additions & 24 deletions

File tree

test/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ endif()
4545
find_package(Threads)
4646
find_package(doctest)
4747

48+
cmake_policy(SET CMP0167 OLD) # use find boost from old cmake
49+
find_package(Boost REQUIRED COMPONENTS process filesystem)
50+
4851
include_directories(${GTEST_INCLUDE_DIRS} SYSTEM)
4952

5053
set(XEUS_PYTHON_TESTS
@@ -71,7 +74,7 @@ set_target_properties(test_xeus_python PROPERTIES
7174
)
7275

7376
include_directories(${PYTHON_INCLUDE_DIRS})
74-
target_link_libraries(test_xeus_python ${PYTHON_LIBRARIES} xeus-zmq doctest::doctest ${CMAKE_THREAD_LIBS_INIT})
77+
target_link_libraries(test_xeus_python ${PYTHON_LIBRARIES} xeus-zmq doctest::doctest Boost::headers Boost::filesystem Boost::process ${CMAKE_THREAD_LIBS_INIT})
7578
target_include_directories(test_xeus_python PRIVATE ${XEUS_PYTHON_INCLUDE_DIR})
7679

7780
add_custom_target(xtest COMMAND test_xeus_python DEPENDS test_xeus_python)

test/test_debugger.cpp

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
#include <unistd.h>
3636
#endif
3737

38+
#ifndef WIN32_LEAN_AND_MEAN
39+
#define WIN32_LEAN_AND_MEAN
40+
#endif
41+
#include <boost/process.hpp>
42+
3843
/***********************************
3944
* Should be moved in a utils file *
4045
***********************************/
@@ -1147,19 +1152,25 @@ void dump_connection_file()
11471152
}
11481153
}
11491154

1150-
void start_kernel()
1155+
struct KernelProcess
11511156
{
1152-
dump_connection_file();
1153-
std::string cmd = "xpython -f " + KERNEL_JSON + "&";
1154-
int ret2 = std::system(cmd.c_str());
1155-
std::this_thread::sleep_for(4s);
1156-
}
1157+
KernelProcess()
1158+
{
1159+
std::this_thread::sleep_for(2s);
1160+
}
1161+
1162+
private:
1163+
1164+
bool _ = [] { dump_connection_file(); return true; }();
1165+
boost::asio::io_context ctx;
1166+
boost::process::process process{ ctx, boost::process::environment::find_executable("xpython"), { "-f" , KERNEL_JSON } };
1167+
};
11571168

11581169
TEST_SUITE("debugger")
11591170
{
11601171
TEST_CASE("init")
11611172
{
1162-
start_kernel();
1173+
KernelProcess xpython_process;
11631174
timer t;
11641175
auto context_ptr = xeus::make_zmq_context();
11651176
{
@@ -1176,7 +1187,7 @@ TEST_SUITE("debugger")
11761187

11771188
TEST_CASE("disconnect")
11781189
{
1179-
start_kernel();
1190+
KernelProcess xpython_process;
11801191
timer t;
11811192
auto context_ptr = xeus::make_zmq_context();
11821193
{
@@ -1192,7 +1203,7 @@ TEST_SUITE("debugger")
11921203

11931204
TEST_CASE("attach")
11941205
{
1195-
start_kernel();
1206+
KernelProcess xpython_process;
11961207
timer t;
11971208
auto context_ptr = xeus::make_zmq_context();
11981209
{
@@ -1209,7 +1220,7 @@ TEST_SUITE("debugger")
12091220

12101221
TEST_CASE("multisession")
12111222
{
1212-
start_kernel();
1223+
KernelProcess xpython_process;
12131224
timer t;
12141225
auto context_ptr = xeus::make_zmq_context();
12151226
{
@@ -1228,7 +1239,7 @@ TEST_SUITE("debugger")
12281239

12291240
TEST_CASE("set_external_breakpoints")
12301241
{
1231-
start_kernel();
1242+
KernelProcess xpython_process;
12321243
timer t;
12331244
auto context_ptr = xeus::make_zmq_context();
12341245
{
@@ -1247,7 +1258,7 @@ TEST_SUITE("debugger")
12471258
/*
12481259
TEST_CASE("external_next_continue")
12491260
{
1250-
start_kernel();
1261+
KernelProcess xpython_process;
12511262
timer t;
12521263
auto context_ptr = xeus::make_zmq_context();
12531264
{
@@ -1264,7 +1275,7 @@ TEST_SUITE("debugger")
12641275
*/
12651276
TEST_CASE("set_breakpoints")
12661277
{
1267-
start_kernel();
1278+
KernelProcess xpython_process;
12681279
timer t;
12691280
auto context_ptr = xeus::make_zmq_context();
12701281
{
@@ -1281,7 +1292,7 @@ TEST_SUITE("debugger")
12811292

12821293
TEST_CASE("set_exception_breakpoints")
12831294
{
1284-
start_kernel();
1295+
KernelProcess xpython_process;
12851296
timer t;
12861297
auto context_ptr = xeus::make_zmq_context();
12871298
{
@@ -1298,7 +1309,7 @@ TEST_SUITE("debugger")
12981309

12991310
TEST_CASE("source")
13001311
{
1301-
start_kernel();
1312+
KernelProcess xpython_process;
13021313
timer t;
13031314
auto context_ptr = xeus::make_zmq_context();
13041315
{
@@ -1317,7 +1328,7 @@ TEST_SUITE("debugger")
13171328
/*
13181329
TEST_CASE("next_continue")
13191330
{
1320-
start_kernel();
1331+
KernelProcess xpython_process;
13211332
timer t;
13221333
auto context_ptr = xeus::make_zmq_context();
13231334
{
@@ -1337,7 +1348,7 @@ TEST_SUITE("debugger")
13371348
/*
13381349
TEST_CASE("stepin")
13391350
{
1340-
start_kernel();
1351+
KernelProcess xpython_process;
13411352
timer t;
13421353
auto context_ptr = xeus::make_zmq_context();
13431354
{
@@ -1355,7 +1366,7 @@ TEST_SUITE("debugger")
13551366

13561367
TEST_CASE("stack_trace")
13571368
{
1358-
start_kernel();
1369+
KernelProcess xpython_process;
13591370
timer t;
13601371
auto context_ptr = xeus::make_zmq_context();
13611372
{
@@ -1372,7 +1383,7 @@ TEST_SUITE("debugger")
13721383

13731384
TEST_CASE("debug_info")
13741385
{
1375-
start_kernel();
1386+
KernelProcess xpython_process;
13761387
timer t;
13771388
auto context_ptr = xeus::make_zmq_context();
13781389
{
@@ -1389,7 +1400,7 @@ TEST_SUITE("debugger")
13891400

13901401
TEST_CASE("inspect_variables")
13911402
{
1392-
start_kernel();
1403+
KernelProcess xpython_process;
13931404
timer t;
13941405
auto context_ptr = xeus::make_zmq_context();
13951406
{
@@ -1408,7 +1419,7 @@ TEST_SUITE("debugger")
14081419
/*
14091420
TEST_CASE("rich_inspect_variables")
14101421
{
1411-
start_kernel();
1422+
KernelProcess xpython_process;
14121423
timer t;
14131424
auto context_ptr = xeus::make_zmq_context();
14141425
{
@@ -1425,7 +1436,7 @@ TEST_SUITE("debugger")
14251436

14261437
TEST_CASE("variables")
14271438
{
1428-
start_kernel();
1439+
KernelProcess xpython_process;
14291440
timer t;
14301441
auto context_ptr = xeus::make_zmq_context();
14311442
{
@@ -1442,7 +1453,7 @@ TEST_SUITE("debugger")
14421453

14431454
TEST_CASE("copy_to_globals")
14441455
{
1445-
start_kernel();
1456+
KernelProcess xpython_process;
14461457
timer t;
14471458
auto context_ptr = xeus::make_zmq_context();
14481459
{

0 commit comments

Comments
 (0)