peerplays-fc/tests/io/tcp_test.cpp
John M. Jones 0d689a4894
Remove hard coded number of IO threads (#47)
This allows for control of the number of IO threads before their creation
2018-05-16 09:44:23 -07:00

58 lines
1.4 KiB
C++

#include <boost/test/unit_test.hpp>
#include <fc/network/tcp_socket.hpp>
#include <fc/asio.hpp>
BOOST_AUTO_TEST_SUITE(tcp_tests)
/***
* Running this test through valgrind will show
* a memory leak due to lack of logic in destructor.
* See https://github.com/bitshares/bitshares-fc/blob/51688042b0b9f99f03224f54fb937fe024fe5ced/src/asio.cpp#L152
*/
BOOST_AUTO_TEST_CASE(tcpconstructor_test)
{
fc::tcp_socket socket;
}
class my_io_class : public fc::asio::default_io_service_scope
{
public:
uint16_t get_num_threads()
{
return fc::asio::default_io_service_scope::num_io_threads;
}
static void reset_num_threads() { fc::asio::default_io_service_scope::num_io_threads = 0; }
};
/***
* Test the control of number of threads from outside
*/
BOOST_AUTO_TEST_CASE( number_threads_test )
{
// to erase leftovers from previous tests
my_io_class::reset_num_threads();
fc::asio::default_io_service_scope::set_num_threads(12);
my_io_class my_class;
BOOST_CHECK_EQUAL( 12, my_class.get_num_threads() );
}
/***
* Test the control of number of threads from outside
*/
BOOST_AUTO_TEST_CASE( default_number_threads_test )
{
// to erase leftovers from previous tests
my_io_class::reset_num_threads();
my_io_class my_class;
fc::asio::default_io_service();
BOOST_CHECK( my_class.get_num_threads() > 1 );
}
BOOST_AUTO_TEST_SUITE_END()