From 161d969e0eabfecccd69a6b9ed2d03919cf89cb5 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 18 Nov 2018 16:24:30 -0500 Subject: improve the test programs --- test/test_p2p_stress.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'test/test_p2p_stress.cpp') diff --git a/test/test_p2p_stress.cpp b/test/test_p2p_stress.cpp index b58bcc7..ac6168a 100644 --- a/test/test_p2p_stress.cpp +++ b/test/test_p2p_stress.cpp @@ -44,6 +44,7 @@ using salticidae::bytearray_t; using salticidae::uint256_t; using salticidae::static_pointer_cast; using salticidae::Config; +using salticidae::ThreadCall; using std::placeholders::_1; using std::placeholders::_2; @@ -159,15 +160,19 @@ int main(int argc, char **argv) { for (int i = 0; i < opt_npeers->get(); i++) addrs.push_back(NetAddr("127.0.0.1:" + std::to_string(12345 + i))); std::vector peers; + std::vector> tcalls; + tcalls.resize(addrs.size()); + size_t i = 0; for (auto &addr: addrs) { - peers.push_back(std::thread([&, addr]() { + peers.push_back(std::thread([&, addr, i]() { EventContext ec; std::unordered_map tc; MyNet net(ec, MyNet::Config( salticidae::ConnPool::Config() .nworker(opt_nworker->get()).seg_buff_size(seg_buff_size)) .conn_timeout(5).ping_period(2)); + tcalls[i] = new ThreadCall(ec); if (!opt_no_msg->get()) install_proto(ec, net, tc, seg_buff_size); try { @@ -178,7 +183,22 @@ int main(int argc, char **argv) { ec.dispatch(); } catch (salticidae::SalticidaeError &e) {} })); + i++; } - for (auto &t: peers) t.join(); + + EventContext ec; + auto shutdown = [&](int) { + for (auto &tc: tcalls) + tc->async_call([ec=tc->get_ec()](ThreadCall::Handle &) { + ec.stop(); + }); + for (auto &t: peers) t.join(); + ec.stop(); + }; + salticidae::SigEvent ev_sigint(ec, shutdown); + salticidae::SigEvent ev_sigterm(ec, shutdown); + ev_sigint.add(SIGINT); + ev_sigterm.add(SIGTERM); + ec.dispatch(); return 0; } -- cgit v1.2.3