Skip to content

Commit

Permalink
Fix TSAN error with test confirmation_height.conflict_rollback_cement…
Browse files Browse the repository at this point in the history
…ed (#2002)

* Fix TSAN error with confirmation_height.conflict_rollback_cemented

* Fix rpc.confirmation_height_currently_processing when running slowly (i.e ASAN)
  • Loading branch information
wezrule committed May 21, 2019
1 parent dd797db commit f230c88
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
9 changes: 5 additions & 4 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <boost/iostreams/stream_buffer.hpp>
#include <boost/thread.hpp>
#include <gtest/gtest.h>
#include <nano/core_test/testutil.hpp>
Expand Down Expand Up @@ -1954,6 +1955,9 @@ TEST (confirmation_height, all_block_types)
/* Bulk of the this test was taken from the node.fork_flip test */
TEST (confirmation_height, conflict_rollback_cemented)
{
boost::iostreams::stream_buffer<nano::stringstream_mt_sink> sb;
sb.open (nano::stringstream_mt_sink{});
nano::boost_log_cerr_redirect redirect_cerr (&sb);
nano::system system (24000, 2);
auto & node1 (*system.nodes[0]);
auto & node2 (*system.nodes[1]);
Expand Down Expand Up @@ -2005,16 +2009,13 @@ TEST (confirmation_height, conflict_rollback_cemented)
node1.store.account_put (transaction, nano::genesis_account, info);
}

std::stringstream ss;
nano::boost_log_cerr_redirect redirect_cerr (ss.rdbuf ());

auto rollback_log_entry = boost::str (boost::format ("Failed to roll back %1%") % send2->hash ().to_string ());
system.deadline_set (10s);
auto done (false);
while (!done)
{
ASSERT_NO_ERROR (system.poll ());
done = (ss.str ().find (rollback_log_entry) != std::string::npos);
done = (sb.component ()->str ().find (rollback_log_entry) != std::string::npos);
}
auto transaction1 (system.nodes[0]->store.tx_begin_read ());
auto transaction2 (system.nodes[1]->store.tx_begin_read ());
Expand Down
29 changes: 29 additions & 0 deletions nano/core_test/testutil.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <atomic>
#include <boost/iostreams/concepts.hpp>
#include <boost/log/sources/logger.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/multiprecision/cpp_int.hpp>
Expand Down Expand Up @@ -43,6 +44,34 @@ extern nano::uint256_union const & genesis_account;
extern nano::uint256_union const & burn_account;
extern nano::uint128_t const & genesis_amount;

class stringstream_mt_sink : public boost::iostreams::sink
{
public:
stringstream_mt_sink () = default;
stringstream_mt_sink (const stringstream_mt_sink & sink)
{
std::lock_guard<std::mutex> guard (mutex);
ss << sink.ss.str ();
}

std::streamsize write (const char * string_to_write, std::streamsize size)
{
std::lock_guard<std::mutex> guard (mutex);
ss << string_to_write;
return size;
}

std::string str ()
{
std::lock_guard<std::mutex> guard (mutex);
return ss.str ();
}

private:
mutable std::mutex mutex;
std::stringstream ss;
};

class boost_log_cerr_redirect
{
public:
Expand Down
2 changes: 1 addition & 1 deletion nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5378,7 +5378,7 @@ TEST (rpc, confirmation_height_currently_processing)
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);

// Do enough blocks to reliably call RPC before the confirmation height has finished
constexpr auto num_blocks = 500;
constexpr auto num_blocks = 1000;
auto previous_genesis_chain_hash = node->latest (nano::test_genesis_key.pub);
{
auto transaction = node->store.tx_begin_write ();
Expand Down

0 comments on commit f230c88

Please sign in to comment.