diff options
author | Determinant <[email protected]> | 2018-11-14 22:18:59 -0500 |
---|---|---|
committer | Determinant <[email protected]> | 2018-11-14 22:18:59 -0500 |
commit | ecc163f98e434b557768560d00ee2f9755d6d950 (patch) | |
tree | 7cb9d04ba0dc4761968cd79de0c9be5aab3aa6e4 /test | |
parent | 0f341fe7f092f704e1c1952c72085eb1ebd2086a (diff) |
major bug fix
Diffstat (limited to 'test')
-rw-r--r-- | test/bench_network.cpp | 12 | ||||
-rw-r--r-- | test/test_network.cpp | 25 | ||||
-rw-r--r-- | test/test_p2p.cpp | 25 | ||||
-rw-r--r-- | test/test_queue.cpp | 5 |
4 files changed, 42 insertions, 25 deletions
diff --git a/test/bench_network.cpp b/test/bench_network.cpp index 8ff9ab2..40ba17a 100644 --- a/test/bench_network.cpp +++ b/test/bench_network.cpp @@ -82,17 +82,17 @@ struct MyNet: public MsgNetworkByteOp { MsgNetwork<opcode_t>(ec, 10, 1.0, 4096), name(name), peer(peer), - ev_period_stat(ec, -1, 0, [this, stat_timeout](int, short) { + ev_period_stat(ec, -1, [this, stat_timeout](int, short) { printf("%.2f mps\n", nrecv / (double)stat_timeout); nrecv = 0; - ev_period_stat.add_with_timeout(stat_timeout); + ev_period_stat.add_with_timeout(stat_timeout, 0); }), nrecv(0) { /* message handler could be a bound method */ reg_handler(salticidae::generic_bind( &MyNet::on_receive_bytes, this, _1, _2)); if (stat_timeout > 0) - ev_period_stat.add_with_timeout(0); + ev_period_stat.add_with_timeout(0, 0); } struct Conn: public MsgNetworkByteOp::Conn { @@ -109,12 +109,12 @@ struct MyNet: public MsgNetworkByteOp { printf("[%s] Connected, sending hello.\n", net->name.c_str()); /* send the first message through this connection */ - net->ev_period_send = Event(net->ec, -1, 0, + net->ev_period_send = Event(net->ec, -1, [net, conn = self()](int, short) { net->send_msg(MsgBytes(256), *conn); - net->ev_period_send.add_with_timeout(0); + net->ev_period_send.add_with_timeout(0, 0); }); - net->ev_period_send.add_with_timeout(0); + net->ev_period_send.add_with_timeout(0, 0); } else diff --git a/test/test_network.cpp b/test/test_network.cpp index d93d0ff..d52b6c2 100644 --- a/test/test_network.cpp +++ b/test/test_network.cpp @@ -132,7 +132,14 @@ salticidae::EventContext ec; NetAddr alice_addr("127.0.0.1:12345"); NetAddr bob_addr("127.0.0.1:12346"); +void signal_handler(int) { + throw salticidae::SalticidaeError("got termination signal"); +} + int main() { + signal(SIGTERM, signal_handler); + signal(SIGINT, signal_handler); + /* test two nodes */ MyNet alice(ec, "Alice", bob_addr); MyNet bob(ec, "Bob", alice_addr); @@ -141,16 +148,18 @@ int main() { alice.reg_handler(on_receive_ack); bob.reg_handler(on_receive_ack); - alice.start(); - bob.start(); + try { + alice.start(); + bob.start(); - alice.listen(alice_addr); - bob.listen(bob_addr); + alice.listen(alice_addr); + bob.listen(bob_addr); - /* first attempt */ - alice.connect(bob_addr); - bob.connect(alice_addr); + /* first attempt */ + alice.connect(bob_addr); + bob.connect(alice_addr); - ec.dispatch(); + ec.dispatch(); + } catch (salticidae::SalticidaeError &e) {} return 0; } diff --git a/test/test_p2p.cpp b/test/test_p2p.cpp index f52f48f..558be5c 100644 --- a/test/test_p2p.cpp +++ b/test/test_p2p.cpp @@ -130,7 +130,14 @@ salticidae::EventContext ec; NetAddr alice_addr("127.0.0.1:12345"); NetAddr bob_addr("127.0.0.1:12346"); +void signal_handler(int) { + throw salticidae::SalticidaeError("got termination signal"); +} + int main() { + signal(SIGTERM, signal_handler); + signal(SIGINT, signal_handler); + /* test two nodes */ MyNet alice(ec, "Alice", bob_addr); MyNet bob(ec, "Bob", alice_addr); @@ -139,16 +146,18 @@ int main() { alice.reg_handler(on_receive_ack); bob.reg_handler(on_receive_ack); - alice.start(); - bob.start(); + try { + alice.start(); + bob.start(); - alice.listen(alice_addr); - bob.listen(bob_addr); + alice.listen(alice_addr); + bob.listen(bob_addr); - /* first attempt */ - alice.add_peer(bob_addr); - bob.add_peer(alice_addr); + /* first attempt */ + alice.add_peer(bob_addr); + bob.add_peer(alice_addr); - ec.dispatch(); + ec.dispatch(); + } catch (salticidae::SalticidaeError &e) {} return 0; } diff --git a/test/test_queue.cpp b/test/test_queue.cpp index a2444d3..5a7b548 100644 --- a/test/test_queue.cpp +++ b/test/test_queue.cpp @@ -23,11 +23,10 @@ void test_mpsc(int nproducers = 16, int nops = 100000, size_t burst_size = 128) }); std::vector<std::thread> producers; std::thread consumer([&collected, total, &ec]() { - salticidae::Event timer(ec, -1, EV_TIMEOUT | EV_PERSIST, - [&ec, &collected, total](int, short) { + salticidae::Event timer(ec, -1, [&ec, &collected, total](int, short) { if (collected.load() == total) ec.stop(); }); - timer.add_with_timeout(1); + timer.add_with_timeout(1, EV_TIMEOUT | EV_PERSIST); ec.dispatch(); }); for (int i = 0; i < nproducers; i++) |