32 #include <boost/chrono/chrono.hpp> 33 #include <boost/thread/condition_variable.hpp> 34 #include <boost/thread/mutex.hpp> 36 #include "gtest/gtest.h" 44 const uint32_t test_server_port = 5626;
51 struct test_protocol_handler_config
55 struct test_protocol_handler
57 typedef test_connection_context connection_context;
58 typedef test_protocol_handler_config config_type;
64 void after_init_connection()
68 void handle_qued_callback()
72 bool release_protocol()
77 bool handle_recv(
const void* ,
size_t )
86 TEST(boosted_tcp_server, worker_threads_are_exception_resistant)
89 ASSERT_TRUE(srv.init_server(test_server_port, test_server_host));
92 boost::condition_variable cond;
95 auto counter_incrementer = [&counter, &cond, &mtx]()
97 boost::unique_lock<boost::mutex> lock(mtx);
107 ASSERT_TRUE(srv.async_call([&counter_incrementer]() { counter_incrementer(); throw std::runtime_error(
"test 1"); }));
108 ASSERT_TRUE(srv.async_call([&counter_incrementer]() { counter_incrementer(); throw std::string(
"test 2"); }));
109 ASSERT_TRUE(srv.async_call([&counter_incrementer]() { counter_incrementer(); throw
"test 3"; }));
110 ASSERT_TRUE(srv.async_call([&counter_incrementer]() { counter_incrementer(); throw 4; }));
113 boost::unique_lock<boost::mutex> lock(mtx);
114 ASSERT_NE(boost::cv_status::timeout, cond.wait_for(lock, boost::chrono::seconds(5)));
127 boost::unique_lock<boost::mutex> lock(mtx);
128 ASSERT_NE(boost::cv_status::timeout, cond.wait_for(lock, boost::chrono::seconds(5)));
132 srv.send_stop_signal();
epee::net_utils::boosted_tcp_server< test_levin_protocol_handler > test_tcp_server
#define ASSERT_EQ(val1, val2)
the connection templated-class for one peer connection
TEST(boosted_tcp_server, worker_threads_are_exception_resistant)
#define ASSERT_TRUE(condition)
#define ASSERT_NE(val1, val2)