switch to boost::thread for mingw build
This commit is contained in:
parent
3f171b931f
commit
2cde2c02ca
|
@ -41,8 +41,10 @@ target_link_libraries(libwallet_api_tests
|
||||||
PRIVATE
|
PRIVATE
|
||||||
wallet
|
wallet
|
||||||
epee
|
epee
|
||||||
|
${Boost_CHRONO_LIBRARY}
|
||||||
${Boost_SERIALIZATION_LIBRARY}
|
${Boost_SERIALIZATION_LIBRARY}
|
||||||
${Boost_FILESYSTEM_LIBRARY}
|
${Boost_FILESYSTEM_LIBRARY}
|
||||||
|
${Boost_THREAD_LIBRARY}
|
||||||
${Boost_SYSTEM_LIBRARY}
|
${Boost_SYSTEM_LIBRARY}
|
||||||
${GTEST_LIBRARIES}
|
${GTEST_LIBRARIES}
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
|
|
|
@ -34,18 +34,19 @@
|
||||||
#include "wallet/wallet2.h"
|
#include "wallet/wallet2.h"
|
||||||
#include "include_base_utils.h"
|
#include "include_base_utils.h"
|
||||||
|
|
||||||
|
#include <boost/chrono/chrono.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
#include <boost/thread/condition_variable.hpp>
|
||||||
|
#include <boost/thread/mutex.hpp>
|
||||||
|
#include <boost/thread/thread.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <mutex>
|
|
||||||
#include <thread>
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <condition_variable>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -254,15 +255,15 @@ TEST_F(WalletManagerTest, WalletAmountFromString)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void open_wallet_helper(Monero::WalletManager *wmgr, Monero::Wallet **wallet, const std::string &pass, std::mutex *mutex)
|
void open_wallet_helper(Monero::WalletManager *wmgr, Monero::Wallet **wallet, const std::string &pass, boost::mutex *mutex)
|
||||||
{
|
{
|
||||||
if (mutex)
|
if (mutex)
|
||||||
mutex->lock();
|
mutex->lock();
|
||||||
LOG_PRINT_L3("opening wallet in thread: " << std::this_thread::get_id());
|
LOG_PRINT_L3("opening wallet in thread: " << boost::this_thread::get_id());
|
||||||
*wallet = wmgr->openWallet(WALLET_NAME, pass, true);
|
*wallet = wmgr->openWallet(WALLET_NAME, pass, true);
|
||||||
LOG_PRINT_L3("wallet address: " << (*wallet)->address());
|
LOG_PRINT_L3("wallet address: " << (*wallet)->address());
|
||||||
LOG_PRINT_L3("wallet status: " << (*wallet)->status());
|
LOG_PRINT_L3("wallet status: " << (*wallet)->status());
|
||||||
LOG_PRINT_L3("closing wallet in thread: " << std::this_thread::get_id());
|
LOG_PRINT_L3("closing wallet in thread: " << boost::this_thread::get_id());
|
||||||
if (mutex)
|
if (mutex)
|
||||||
mutex->unlock();
|
mutex->unlock();
|
||||||
}
|
}
|
||||||
|
@ -307,7 +308,7 @@ TEST_F(WalletManagerTest, WalletManagerOpensWalletWithPasswordAndReopen)
|
||||||
|
|
||||||
Monero::Wallet *wallet2 = nullptr;
|
Monero::Wallet *wallet2 = nullptr;
|
||||||
Monero::Wallet *wallet3 = nullptr;
|
Monero::Wallet *wallet3 = nullptr;
|
||||||
std::mutex mutex;
|
boost::mutex mutex;
|
||||||
|
|
||||||
open_wallet_helper(wmgr, &wallet2, wrong_wallet_pass, nullptr);
|
open_wallet_helper(wmgr, &wallet2, wrong_wallet_pass, nullptr);
|
||||||
ASSERT_TRUE(wallet2 != nullptr);
|
ASSERT_TRUE(wallet2 != nullptr);
|
||||||
|
@ -785,12 +786,12 @@ struct MyWalletListener : public Monero::WalletListener
|
||||||
Monero::Wallet * wallet;
|
Monero::Wallet * wallet;
|
||||||
uint64_t total_tx;
|
uint64_t total_tx;
|
||||||
uint64_t total_rx;
|
uint64_t total_rx;
|
||||||
std::mutex mutex;
|
boost::mutex mutex;
|
||||||
std::condition_variable cv_send;
|
boost::condition_variable cv_send;
|
||||||
std::condition_variable cv_receive;
|
boost::condition_variable cv_receive;
|
||||||
std::condition_variable cv_update;
|
boost::condition_variable cv_update;
|
||||||
std::condition_variable cv_refresh;
|
boost::condition_variable cv_refresh;
|
||||||
std::condition_variable cv_newblock;
|
boost::condition_variable cv_newblock;
|
||||||
bool send_triggered;
|
bool send_triggered;
|
||||||
bool receive_triggered;
|
bool receive_triggered;
|
||||||
bool newblock_triggered;
|
bool newblock_triggered;
|
||||||
|
@ -880,8 +881,8 @@ TEST_F(WalletTest2, WalletCallBackRefreshedSync)
|
||||||
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
||||||
ASSERT_TRUE(wallet_src_listener->refresh_triggered);
|
ASSERT_TRUE(wallet_src_listener->refresh_triggered);
|
||||||
ASSERT_TRUE(wallet_src->connected());
|
ASSERT_TRUE(wallet_src->connected());
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(60*3);
|
boost::chrono::seconds wait_for = boost::chrono::seconds(60*3);
|
||||||
std::unique_lock<std::mutex> lock (wallet_src_listener->mutex);
|
boost::unique_lock<boost::mutex> lock (wallet_src_listener->mutex);
|
||||||
wallet_src_listener->cv_refresh.wait_for(lock, wait_for);
|
wallet_src_listener->cv_refresh.wait_for(lock, wait_for);
|
||||||
wmgr->closeWallet(wallet_src);
|
wmgr->closeWallet(wallet_src);
|
||||||
}
|
}
|
||||||
|
@ -895,8 +896,8 @@ TEST_F(WalletTest2, WalletCallBackRefreshedAsync)
|
||||||
Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
||||||
MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src);
|
MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src);
|
||||||
|
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(20);
|
boost::chrono::seconds wait_for = boost::chrono::seconds(20);
|
||||||
std::unique_lock<std::mutex> lock (wallet_src_listener->mutex);
|
boost::unique_lock<boost::mutex> lock (wallet_src_listener->mutex);
|
||||||
wallet_src->init(MAINNET_DAEMON_ADDRESS, 0);
|
wallet_src->init(MAINNET_DAEMON_ADDRESS, 0);
|
||||||
wallet_src->startRefresh();
|
wallet_src->startRefresh();
|
||||||
std::cerr << "TEST: waiting on refresh lock...\n";
|
std::cerr << "TEST: waiting on refresh lock...\n";
|
||||||
|
@ -936,8 +937,8 @@ TEST_F(WalletTest2, WalletCallbackSent)
|
||||||
ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
|
ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
|
||||||
ASSERT_TRUE(tx->commit());
|
ASSERT_TRUE(tx->commit());
|
||||||
|
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(60*3);
|
boost::chrono::seconds wait_for = boost::chrono::seconds(60*3);
|
||||||
std::unique_lock<std::mutex> lock (wallet_src_listener->mutex);
|
boost::unique_lock<boost::mutex> lock (wallet_src_listener->mutex);
|
||||||
std::cerr << "TEST: waiting on send lock...\n";
|
std::cerr << "TEST: waiting on send lock...\n";
|
||||||
wallet_src_listener->cv_send.wait_for(lock, wait_for);
|
wallet_src_listener->cv_send.wait_for(lock, wait_for);
|
||||||
std::cerr << "TEST: send lock acquired...\n";
|
std::cerr << "TEST: send lock acquired...\n";
|
||||||
|
@ -978,8 +979,8 @@ TEST_F(WalletTest2, WalletCallbackReceived)
|
||||||
ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
|
ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
|
||||||
ASSERT_TRUE(tx->commit());
|
ASSERT_TRUE(tx->commit());
|
||||||
|
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(60*4);
|
boost::chrono::seconds wait_for = boost::chrono::seconds(60*4);
|
||||||
std::unique_lock<std::mutex> lock (wallet_dst_listener->mutex);
|
boost::unique_lock<boost::mutex> lock (wallet_dst_listener->mutex);
|
||||||
std::cerr << "TEST: waiting on receive lock...\n";
|
std::cerr << "TEST: waiting on receive lock...\n";
|
||||||
wallet_dst_listener->cv_receive.wait_for(lock, wait_for);
|
wallet_dst_listener->cv_receive.wait_for(lock, wait_for);
|
||||||
std::cerr << "TEST: receive lock acquired...\n";
|
std::cerr << "TEST: receive lock acquired...\n";
|
||||||
|
@ -1011,8 +1012,8 @@ TEST_F(WalletTest2, WalletCallbackNewBlock)
|
||||||
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet_src));
|
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet_src));
|
||||||
|
|
||||||
// wait max 4 min for new block
|
// wait max 4 min for new block
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(60*4);
|
boost::chrono::seconds wait_for = boost::chrono::seconds(60*4);
|
||||||
std::unique_lock<std::mutex> lock (wallet_listener->mutex);
|
boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
|
||||||
std::cerr << "TEST: waiting on newblock lock...\n";
|
std::cerr << "TEST: waiting on newblock lock...\n";
|
||||||
wallet_listener->cv_newblock.wait_for(lock, wait_for);
|
wallet_listener->cv_newblock.wait_for(lock, wait_for);
|
||||||
std::cerr << "TEST: newblock lock acquired...\n";
|
std::cerr << "TEST: newblock lock acquired...\n";
|
||||||
|
@ -1049,8 +1050,8 @@ TEST_F(WalletManagerMainnetTest, CreateAndRefreshWalletMainNetAsync)
|
||||||
Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG);
|
Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG);
|
||||||
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
|
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
|
||||||
|
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(SECONDS_TO_REFRESH);
|
boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH);
|
||||||
std::unique_lock<std::mutex> lock (wallet_listener->mutex);
|
boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
|
||||||
wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
||||||
wallet->startRefresh();
|
wallet->startRefresh();
|
||||||
std::cerr << "TEST: waiting on refresh lock...\n";
|
std::cerr << "TEST: waiting on refresh lock...\n";
|
||||||
|
@ -1075,8 +1076,8 @@ TEST_F(WalletManagerMainnetTest, OpenAndRefreshWalletMainNetAsync)
|
||||||
|
|
||||||
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
|
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
|
||||||
|
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(SECONDS_TO_REFRESH);
|
boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH);
|
||||||
std::unique_lock<std::mutex> lock (wallet_listener->mutex);
|
boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
|
||||||
wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
||||||
wallet->startRefresh();
|
wallet->startRefresh();
|
||||||
std::cerr << "TEST: waiting on refresh lock...\n";
|
std::cerr << "TEST: waiting on refresh lock...\n";
|
||||||
|
@ -1109,8 +1110,8 @@ TEST_F(WalletManagerMainnetTest, RecoverAndRefreshWalletMainNetAsync)
|
||||||
ASSERT_TRUE(wallet->status() == Monero::Wallet::Status_Ok);
|
ASSERT_TRUE(wallet->status() == Monero::Wallet::Status_Ok);
|
||||||
ASSERT_TRUE(wallet->address() == address);
|
ASSERT_TRUE(wallet->address() == address);
|
||||||
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
|
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(SECONDS_TO_REFRESH);
|
boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH);
|
||||||
std::unique_lock<std::mutex> lock (wallet_listener->mutex);
|
boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
|
||||||
wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
wallet->init(MAINNET_DAEMON_ADDRESS, 0);
|
||||||
wallet->startRefresh();
|
wallet->startRefresh();
|
||||||
std::cerr << "TEST: waiting on refresh lock...\n";
|
std::cerr << "TEST: waiting on refresh lock...\n";
|
||||||
|
|
|
@ -44,6 +44,7 @@ target_link_libraries(net_load_tests_clt
|
||||||
${Boost_CHRONO_LIBRARY}
|
${Boost_CHRONO_LIBRARY}
|
||||||
${Boost_DATE_TIME_LIBRARY}
|
${Boost_DATE_TIME_LIBRARY}
|
||||||
${Boost_SYSTEM_LIBRARY}
|
${Boost_SYSTEM_LIBRARY}
|
||||||
|
${Boost_THREAD_LIBARRY}
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
${EXTRA_LIBRARIES})
|
${EXTRA_LIBRARIES})
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <thread>
|
#include <boost/thread/thread.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
@ -191,7 +191,7 @@ namespace
|
||||||
protected:
|
protected:
|
||||||
virtual void SetUp()
|
virtual void SetUp()
|
||||||
{
|
{
|
||||||
m_thread_count = (std::max)(min_thread_count, std::thread::hardware_concurrency() / 2);
|
m_thread_count = (std::max)(min_thread_count, boost::thread::hardware_concurrency() / 2);
|
||||||
|
|
||||||
m_tcp_server.get_config_object().m_pcommands_handler = &m_commands_handler;
|
m_tcp_server.get_config_object().m_pcommands_handler = &m_commands_handler;
|
||||||
m_tcp_server.get_config_object().m_invoke_timeout = CONNECTION_TIMEOUT;
|
m_tcp_server.get_config_object().m_invoke_timeout = CONNECTION_TIMEOUT;
|
||||||
|
@ -278,10 +278,10 @@ namespace
|
||||||
void parallel_exec(const Func& func)
|
void parallel_exec(const Func& func)
|
||||||
{
|
{
|
||||||
unit_test::call_counter properly_finished_threads;
|
unit_test::call_counter properly_finished_threads;
|
||||||
std::vector<std::thread> threads(m_thread_count);
|
std::vector<boost::thread> threads(m_thread_count);
|
||||||
for (size_t i = 0; i < threads.size(); ++i)
|
for (size_t i = 0; i < threads.size(); ++i)
|
||||||
{
|
{
|
||||||
threads[i] = std::thread([&, i] {
|
threads[i] = boost::thread([&, i] {
|
||||||
call_func(i, func, 0);
|
call_func(i, func, 0);
|
||||||
properly_finished_threads.inc();
|
properly_finished_threads.inc();
|
||||||
});
|
});
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
//
|
//
|
||||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||||
|
|
||||||
#include <mutex>
|
#include <boost/thread/mutex.hpp>
|
||||||
#include <thread>
|
#include <boost/thread/thread.hpp>
|
||||||
|
|
||||||
#include "include_base_utils.h"
|
#include "include_base_utils.h"
|
||||||
#include "misc_log_ex.h"
|
#include "misc_log_ex.h"
|
||||||
|
@ -58,7 +58,7 @@ namespace
|
||||||
|
|
||||||
//std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
//std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(m_open_close_test_mutex);
|
boost::unique_lock<boost::mutex> lock(m_open_close_test_mutex);
|
||||||
if (!m_open_close_test_conn_id.is_nil())
|
if (!m_open_close_test_conn_id.is_nil())
|
||||||
{
|
{
|
||||||
EXIT_ON_ERROR(m_open_close_test_helper->handle_new_connection(context.m_connection_id, true));
|
EXIT_ON_ERROR(m_open_close_test_helper->handle_new_connection(context.m_connection_id, true));
|
||||||
|
@ -69,7 +69,7 @@ namespace
|
||||||
{
|
{
|
||||||
test_levin_commands_handler::on_connection_close(context);
|
test_levin_commands_handler::on_connection_close(context);
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(m_open_close_test_mutex);
|
boost::unique_lock<boost::mutex> lock(m_open_close_test_mutex);
|
||||||
if (context.m_connection_id == m_open_close_test_conn_id)
|
if (context.m_connection_id == m_open_close_test_conn_id)
|
||||||
{
|
{
|
||||||
LOG_PRINT_L0("Stop open/close test");
|
LOG_PRINT_L0("Stop open/close test");
|
||||||
|
@ -115,7 +115,7 @@ namespace
|
||||||
|
|
||||||
int handle_start_open_close_test(int command, const CMD_START_OPEN_CLOSE_TEST::request& req, CMD_START_OPEN_CLOSE_TEST::response&, test_connection_context& context)
|
int handle_start_open_close_test(int command, const CMD_START_OPEN_CLOSE_TEST::request& req, CMD_START_OPEN_CLOSE_TEST::response&, test_connection_context& context)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(m_open_close_test_mutex);
|
boost::unique_lock<boost::mutex> lock(m_open_close_test_mutex);
|
||||||
if (0 == m_open_close_test_helper.get())
|
if (0 == m_open_close_test_helper.get())
|
||||||
{
|
{
|
||||||
LOG_PRINT_L0("Start open/close test (" << req.open_request_target << ", " << req.max_opened_conn_count << ")");
|
LOG_PRINT_L0("Start open/close test (" << req.open_request_target << ", " << req.max_opened_conn_count << ")");
|
||||||
|
@ -208,7 +208,7 @@ namespace
|
||||||
test_tcp_server& m_tcp_server;
|
test_tcp_server& m_tcp_server;
|
||||||
|
|
||||||
boost::uuids::uuid m_open_close_test_conn_id;
|
boost::uuids::uuid m_open_close_test_conn_id;
|
||||||
std::mutex m_open_close_test_mutex;
|
boost::mutex m_open_close_test_mutex;
|
||||||
std::unique_ptr<open_close_test_helper> m_open_close_test_helper;
|
std::unique_ptr<open_close_test_helper> m_open_close_test_helper;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ int main(int argc, char** argv)
|
||||||
//set up logging options
|
//set up logging options
|
||||||
mlog_configure(mlog_get_default_log_path("net_load_tests_srv.log"), true);
|
mlog_configure(mlog_get_default_log_path("net_load_tests_srv.log"), true);
|
||||||
|
|
||||||
size_t thread_count = (std::max)(min_thread_count, std::thread::hardware_concurrency() / 2);
|
size_t thread_count = (std::max)(min_thread_count, boost::thread::hardware_concurrency() / 2);
|
||||||
|
|
||||||
test_tcp_server tcp_server(epee::net_utils::e_connection_type_RPC);
|
test_tcp_server tcp_server(epee::net_utils::e_connection_type_RPC);
|
||||||
if (!tcp_server.init_server(srv_port, "127.0.0.1"))
|
if (!tcp_server.init_server(srv_port, "127.0.0.1"))
|
||||||
|
|
|
@ -75,6 +75,8 @@ target_link_libraries(unit_tests
|
||||||
wallet
|
wallet
|
||||||
p2p
|
p2p
|
||||||
epee
|
epee
|
||||||
|
${Boost_CHRONO_LIBRARY}
|
||||||
|
${Boost_THREAD_LIBRARY}
|
||||||
${GTEST_LIBRARIES}
|
${GTEST_LIBRARIES}
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
${EXTRA_LIBRARIES})
|
${EXTRA_LIBRARIES})
|
||||||
|
|
|
@ -28,10 +28,9 @@
|
||||||
//
|
//
|
||||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||||
|
|
||||||
#include <condition_variable>
|
#include <boost/chrono/chrono.hpp>
|
||||||
#include <chrono>
|
#include <boost/thread/condition_variable.hpp>
|
||||||
#include <mutex>
|
#include <boost/thread/mutex.hpp>
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
@ -88,13 +87,13 @@ TEST(boosted_tcp_server, worker_threads_are_exception_resistant)
|
||||||
test_tcp_server srv(epee::net_utils::e_connection_type_RPC); // RPC disables network limit for unit tests
|
test_tcp_server srv(epee::net_utils::e_connection_type_RPC); // RPC disables network limit for unit tests
|
||||||
ASSERT_TRUE(srv.init_server(test_server_port, test_server_host));
|
ASSERT_TRUE(srv.init_server(test_server_port, test_server_host));
|
||||||
|
|
||||||
std::mutex mtx;
|
boost::mutex mtx;
|
||||||
std::condition_variable cond;
|
boost::condition_variable cond;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
auto counter_incrementer = [&counter, &cond, &mtx]()
|
auto counter_incrementer = [&counter, &cond, &mtx]()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(mtx);
|
boost::unique_lock<boost::mutex> lock(mtx);
|
||||||
++counter;
|
++counter;
|
||||||
if (4 <= counter)
|
if (4 <= counter)
|
||||||
{
|
{
|
||||||
|
@ -110,8 +109,8 @@ TEST(boosted_tcp_server, worker_threads_are_exception_resistant)
|
||||||
ASSERT_TRUE(srv.async_call([&counter_incrementer]() { counter_incrementer(); throw 4; }));
|
ASSERT_TRUE(srv.async_call([&counter_incrementer]() { counter_incrementer(); throw 4; }));
|
||||||
|
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(mtx);
|
boost::unique_lock<boost::mutex> lock(mtx);
|
||||||
ASSERT_NE(std::cv_status::timeout, cond.wait_for(lock, std::chrono::seconds(5)));
|
ASSERT_NE(boost::cv_status::timeout, cond.wait_for(lock, boost::chrono::seconds(5)));
|
||||||
ASSERT_EQ(4, counter);
|
ASSERT_EQ(4, counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,8 +123,8 @@ TEST(boosted_tcp_server, worker_threads_are_exception_resistant)
|
||||||
ASSERT_TRUE(srv.async_call(counter_incrementer));
|
ASSERT_TRUE(srv.async_call(counter_incrementer));
|
||||||
|
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(mtx);
|
boost::unique_lock<boost::mutex> lock(mtx);
|
||||||
ASSERT_NE(std::cv_status::timeout, cond.wait_for(lock, std::chrono::seconds(5)));
|
ASSERT_NE(boost::cv_status::timeout, cond.wait_for(lock, boost::chrono::seconds(5)));
|
||||||
ASSERT_EQ(4, counter);
|
ASSERT_EQ(4, counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
//
|
//
|
||||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||||
|
|
||||||
#include <mutex>
|
#include <boost/thread/mutex.hpp>
|
||||||
#include <thread>
|
#include <boost/thread/thread.hpp>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ namespace
|
||||||
virtual int invoke(int command, const std::string& in_buff, std::string& buff_out, test_levin_connection_context& context)
|
virtual int invoke(int command, const std::string& in_buff, std::string& buff_out, test_levin_connection_context& context)
|
||||||
{
|
{
|
||||||
m_invoke_counter.inc();
|
m_invoke_counter.inc();
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
boost::unique_lock<boost::mutex> lock(m_mutex);
|
||||||
m_last_command = command;
|
m_last_command = command;
|
||||||
m_last_in_buf = in_buff;
|
m_last_in_buf = in_buff;
|
||||||
buff_out = m_invoke_out_buf;
|
buff_out = m_invoke_out_buf;
|
||||||
|
@ -69,7 +69,7 @@ namespace
|
||||||
virtual int notify(int command, const std::string& in_buff, test_levin_connection_context& context)
|
virtual int notify(int command, const std::string& in_buff, test_levin_connection_context& context)
|
||||||
{
|
{
|
||||||
m_notify_counter.inc();
|
m_notify_counter.inc();
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
boost::unique_lock<boost::mutex> lock(m_mutex);
|
||||||
m_last_command = command;
|
m_last_command = command;
|
||||||
m_last_in_buf = in_buff;
|
m_last_in_buf = in_buff;
|
||||||
return m_return_code;
|
return m_return_code;
|
||||||
|
@ -115,7 +115,7 @@ namespace
|
||||||
unit_test::call_counter m_new_connection_counter;
|
unit_test::call_counter m_new_connection_counter;
|
||||||
unit_test::call_counter m_close_connection_counter;
|
unit_test::call_counter m_close_connection_counter;
|
||||||
|
|
||||||
std::mutex m_mutex;
|
boost::mutex m_mutex;
|
||||||
|
|
||||||
int m_return_code;
|
int m_return_code;
|
||||||
std::string m_invoke_out_buf;
|
std::string m_invoke_out_buf;
|
||||||
|
@ -144,7 +144,7 @@ namespace
|
||||||
{
|
{
|
||||||
//std::cout << "test_connection::do_send()" << std::endl;
|
//std::cout << "test_connection::do_send()" << std::endl;
|
||||||
m_send_counter.inc();
|
m_send_counter.inc();
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
boost::unique_lock<boost::mutex> lock(m_mutex);
|
||||||
m_last_send_data.append(reinterpret_cast<const char*>(ptr), cb);
|
m_last_send_data.append(reinterpret_cast<const char*>(ptr), cb);
|
||||||
return m_send_return;
|
return m_send_return;
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ namespace
|
||||||
size_t send_counter() const { return m_send_counter.get(); }
|
size_t send_counter() const { return m_send_counter.get(); }
|
||||||
|
|
||||||
const std::string& last_send_data() const { return m_last_send_data; }
|
const std::string& last_send_data() const { return m_last_send_data; }
|
||||||
void reset_last_send_data() { std::unique_lock<std::mutex> lock(m_mutex); m_last_send_data.clear(); }
|
void reset_last_send_data() { boost::unique_lock<boost::mutex> lock(m_mutex); m_last_send_data.clear(); }
|
||||||
|
|
||||||
bool send_return() const { return m_send_return; }
|
bool send_return() const { return m_send_return; }
|
||||||
void send_return(bool v) { m_send_return = v; }
|
void send_return(bool v) { m_send_return = v; }
|
||||||
|
@ -172,7 +172,7 @@ namespace
|
||||||
test_levin_connection_context m_context;
|
test_levin_connection_context m_context;
|
||||||
|
|
||||||
unit_test::call_counter m_send_counter;
|
unit_test::call_counter m_send_counter;
|
||||||
std::mutex m_mutex;
|
boost::mutex m_mutex;
|
||||||
|
|
||||||
std::string m_last_send_data;
|
std::string m_last_send_data;
|
||||||
|
|
||||||
|
@ -305,14 +305,14 @@ TEST_F(positive_test_connection_to_levin_protocol_handler_calls, concurent_handl
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const size_t thread_count = std::thread::hardware_concurrency();
|
const size_t thread_count = boost::thread::hardware_concurrency();
|
||||||
std::vector<std::thread> threads(thread_count);
|
std::vector<boost::thread> threads(thread_count);
|
||||||
for (std::thread& th : threads)
|
for (boost::thread& th : threads)
|
||||||
{
|
{
|
||||||
th = std::thread(create_and_destroy_connections);
|
th = boost::thread(create_and_destroy_connections);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::thread& th : threads)
|
for (boost::thread& th : threads)
|
||||||
{
|
{
|
||||||
th.join();
|
th.join();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue