Tests
This commit is contained in:
		
					parent
					
						
							
								ae4e48444d
							
						
					
				
			
			
				commit
				
					
						3a458d86d1
					
				
			
		
					 3 changed files with 50 additions and 54 deletions
				
			
		| 
						 | 
				
			
			@ -562,14 +562,14 @@ TEST (network, peer_max_tcp_attempts)
 | 
			
		|||
	node_config.network.max_peers_per_ip = 3;
 | 
			
		||||
	auto node = system.add_node (node_config, node_flags);
 | 
			
		||||
 | 
			
		||||
	for (auto i (0); i < node_config.network.max_peers_per_ip; ++i)
 | 
			
		||||
	for (auto i = 0; i < node_config.network.max_peers_per_ip; ++i)
 | 
			
		||||
	{
 | 
			
		||||
		auto node2 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work, node_flags));
 | 
			
		||||
		node2->start ();
 | 
			
		||||
		system.nodes.push_back (node2);
 | 
			
		||||
 | 
			
		||||
		// Start TCP attempt
 | 
			
		||||
		node->network.merge_peer (node2->network.endpoint ());
 | 
			
		||||
		// Disable reachout from temporary nodes to avoid mixing outbound and inbound connections
 | 
			
		||||
		nano::node_config temp_config = system.default_config ();
 | 
			
		||||
		temp_config.network.peer_reachout = {};
 | 
			
		||||
		temp_config.network.cached_peer_reachout = {};
 | 
			
		||||
		auto temp_node = system.make_disconnected_node (temp_config, node_flags);
 | 
			
		||||
		ASSERT_TRUE (node->network.merge_peer (temp_node->network.endpoint ()));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ASSERT_TIMELY_EQ (15s, node->network.size (), node_config.network.max_peers_per_ip);
 | 
			
		||||
| 
						 | 
				
			
			@ -752,7 +752,7 @@ TEST (network, expire_duplicate_filter)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// The test must be completed in less than 1 second
 | 
			
		||||
TEST (network, bandwidth_limiter_4_messages)
 | 
			
		||||
TEST (network, DISABLED_bandwidth_limiter_4_messages)
 | 
			
		||||
{
 | 
			
		||||
	nano::test::system system;
 | 
			
		||||
	nano::publish message{ nano::dev::network_params.network, nano::dev::genesis };
 | 
			
		||||
| 
						 | 
				
			
			@ -782,7 +782,7 @@ TEST (network, bandwidth_limiter_4_messages)
 | 
			
		|||
	ASSERT_TIMELY_EQ (1s, 1, node.stats.count (nano::stat::type::drop, nano::stat::detail::publish, nano::stat::dir::out));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST (network, bandwidth_limiter_2_messages)
 | 
			
		||||
TEST (network, DISABLED_bandwidth_limiter_2_messages)
 | 
			
		||||
{
 | 
			
		||||
	nano::test::system system;
 | 
			
		||||
	nano::publish message{ nano::dev::network_params.network, nano::dev::genesis };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,8 +38,7 @@ TEST (request_aggregator, one)
 | 
			
		|||
 | 
			
		||||
	std::vector<std::pair<nano::block_hash, nano::root>> request{ { send1->hash (), send1->root () } };
 | 
			
		||||
 | 
			
		||||
	auto client = std::make_shared<nano::transport::tcp_socket> (node);
 | 
			
		||||
	std::shared_ptr<nano::transport::channel> dummy_channel = std::make_shared<nano::transport::tcp_channel> (node, client);
 | 
			
		||||
	auto dummy_channel = nano::test::fake_channel (node);
 | 
			
		||||
 | 
			
		||||
	// Not yet in the ledger
 | 
			
		||||
	node.aggregator.request (request, dummy_channel);
 | 
			
		||||
| 
						 | 
				
			
			@ -179,8 +178,9 @@ TEST (request_aggregator, two)
 | 
			
		|||
	std::vector<std::pair<nano::block_hash, nano::root>> request;
 | 
			
		||||
	request.emplace_back (send2->hash (), send2->root ());
 | 
			
		||||
	request.emplace_back (receive1->hash (), receive1->root ());
 | 
			
		||||
	auto client = std::make_shared<nano::transport::tcp_socket> (node);
 | 
			
		||||
	std::shared_ptr<nano::transport::channel> dummy_channel = std::make_shared<nano::transport::tcp_channel> (node, client);
 | 
			
		||||
 | 
			
		||||
	auto dummy_channel = nano::test::fake_channel (node);
 | 
			
		||||
 | 
			
		||||
	// Process both blocks
 | 
			
		||||
	node.aggregator.request (request, dummy_channel);
 | 
			
		||||
	// One vote should be generated for both blocks
 | 
			
		||||
| 
						 | 
				
			
			@ -298,8 +298,9 @@ TEST (request_aggregator, split)
 | 
			
		|||
	}
 | 
			
		||||
	ASSERT_TIMELY_EQ (5s, max_vbh + 2, node.ledger.cemented_count ());
 | 
			
		||||
	ASSERT_EQ (max_vbh + 1, request.size ());
 | 
			
		||||
	auto client = std::make_shared<nano::transport::tcp_socket> (node);
 | 
			
		||||
	std::shared_ptr<nano::transport::channel> dummy_channel = std::make_shared<nano::transport::tcp_channel> (node, client);
 | 
			
		||||
 | 
			
		||||
	auto dummy_channel = nano::test::fake_channel (node);
 | 
			
		||||
 | 
			
		||||
	node.aggregator.request (request, dummy_channel);
 | 
			
		||||
	// In the ledger but no vote generated yet
 | 
			
		||||
	ASSERT_TIMELY_EQ (3s, 2, node.stats.count (nano::stat::type::requests, nano::stat::detail::requests_generated_votes));
 | 
			
		||||
| 
						 | 
				
			
			@ -337,8 +338,9 @@ TEST (request_aggregator, channel_max_queue)
 | 
			
		|||
	ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1));
 | 
			
		||||
	std::vector<std::pair<nano::block_hash, nano::root>> request;
 | 
			
		||||
	request.emplace_back (send1->hash (), send1->root ());
 | 
			
		||||
	auto client = std::make_shared<nano::transport::tcp_socket> (node);
 | 
			
		||||
	std::shared_ptr<nano::transport::channel> dummy_channel = std::make_shared<nano::transport::tcp_channel> (node, client);
 | 
			
		||||
 | 
			
		||||
	auto dummy_channel = nano::test::fake_channel (node);
 | 
			
		||||
 | 
			
		||||
	node.aggregator.request (request, dummy_channel);
 | 
			
		||||
	node.aggregator.request (request, dummy_channel);
 | 
			
		||||
	ASSERT_LT (0, node.stats.count (nano::stat::type::aggregator, nano::stat::detail::aggregator_dropped));
 | 
			
		||||
| 
						 | 
				
			
			@ -366,8 +368,9 @@ TEST (request_aggregator, DISABLED_unique)
 | 
			
		|||
	ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1));
 | 
			
		||||
	std::vector<std::pair<nano::block_hash, nano::root>> request;
 | 
			
		||||
	request.emplace_back (send1->hash (), send1->root ());
 | 
			
		||||
	auto client = std::make_shared<nano::transport::tcp_socket> (node);
 | 
			
		||||
	std::shared_ptr<nano::transport::channel> dummy_channel = std::make_shared<nano::transport::tcp_channel> (node, client);
 | 
			
		||||
 | 
			
		||||
	auto dummy_channel = nano::test::fake_channel (node);
 | 
			
		||||
 | 
			
		||||
	node.aggregator.request (request, dummy_channel);
 | 
			
		||||
	node.aggregator.request (request, dummy_channel);
 | 
			
		||||
	node.aggregator.request (request, dummy_channel);
 | 
			
		||||
| 
						 | 
				
			
			@ -410,8 +413,8 @@ TEST (request_aggregator, cannot_vote)
 | 
			
		|||
	// Incorrect hash, correct root
 | 
			
		||||
	request.emplace_back (1, send2->root ());
 | 
			
		||||
 | 
			
		||||
	auto client = std::make_shared<nano::transport::tcp_socket> (node);
 | 
			
		||||
	std::shared_ptr<nano::transport::channel> dummy_channel = std::make_shared<nano::transport::tcp_channel> (node, client);
 | 
			
		||||
	auto dummy_channel = nano::test::fake_channel (node);
 | 
			
		||||
 | 
			
		||||
	node.aggregator.request (request, dummy_channel);
 | 
			
		||||
	ASSERT_TIMELY (3s, node.aggregator.empty ());
 | 
			
		||||
	ASSERT_EQ (1, node.stats.count (nano::stat::type::aggregator, nano::stat::detail::aggregator_accepted));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -126,9 +126,10 @@ TEST (socket, drop_policy)
 | 
			
		|||
	nano::inactive_node inactivenode (nano::unique_path (), node_flags);
 | 
			
		||||
	auto node = inactivenode.node;
 | 
			
		||||
 | 
			
		||||
	std::vector<std::shared_ptr<nano::transport::tcp_socket>> connections;
 | 
			
		||||
	std::atomic completed_writes{ 0 };
 | 
			
		||||
	std::atomic failed_writes{ 0 };
 | 
			
		||||
 | 
			
		||||
	auto func = [&] (size_t total_message_count, nano::transport::buffer_drop_policy drop_policy) {
 | 
			
		||||
	auto func = [&] (size_t total_message_count) {
 | 
			
		||||
		boost::asio::ip::tcp::endpoint endpoint (boost::asio::ip::address_v6::loopback (), system.get_available_port ());
 | 
			
		||||
		boost::asio::ip::tcp::acceptor acceptor (node->io_ctx);
 | 
			
		||||
		acceptor.open (endpoint.protocol ());
 | 
			
		||||
| 
						 | 
				
			
			@ -141,38 +142,39 @@ TEST (socket, drop_policy)
 | 
			
		|||
		});
 | 
			
		||||
 | 
			
		||||
		auto client = std::make_shared<nano::transport::tcp_socket> (*node);
 | 
			
		||||
		auto channel = std::make_shared<nano::transport::tcp_channel> (*node, client);
 | 
			
		||||
 | 
			
		||||
		std::atomic completed_writes{ 0 };
 | 
			
		||||
		completed_writes = 0;
 | 
			
		||||
		failed_writes = 0;
 | 
			
		||||
 | 
			
		||||
		client->async_connect (boost::asio::ip::tcp::endpoint (boost::asio::ip::address_v6::loopback (), acceptor.local_endpoint ().port ()),
 | 
			
		||||
		[&channel, total_message_count, node, &completed_writes, &drop_policy, client] (boost::system::error_code const & ec_a) mutable {
 | 
			
		||||
		[&] (boost::system::error_code const & ec_a) mutable {
 | 
			
		||||
			for (int i = 0; i < total_message_count; i++)
 | 
			
		||||
			{
 | 
			
		||||
				std::vector<uint8_t> buff (1);
 | 
			
		||||
				channel->send_buffer (
 | 
			
		||||
				nano::shared_const_buffer (std::move (buff)), [&completed_writes, client] (boost::system::error_code const & ec, size_t size_a) mutable {
 | 
			
		||||
					client.reset ();
 | 
			
		||||
					++completed_writes;
 | 
			
		||||
				},
 | 
			
		||||
				drop_policy);
 | 
			
		||||
				client->async_write (nano::shared_const_buffer (std::move (buff)), [&] (boost::system::error_code const & ec, size_t size_a) {
 | 
			
		||||
					if (!ec)
 | 
			
		||||
					{
 | 
			
		||||
						++completed_writes;
 | 
			
		||||
					}
 | 
			
		||||
					else
 | 
			
		||||
					{
 | 
			
		||||
						++failed_writes;
 | 
			
		||||
					}
 | 
			
		||||
				});
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		ASSERT_TIMELY_EQ (5s, completed_writes, total_message_count);
 | 
			
		||||
		ASSERT_TIMELY_EQ (5s, completed_writes + failed_writes, total_message_count);
 | 
			
		||||
		ASSERT_EQ (1, client.use_count ());
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	// We're going to write twice the queue size + 1, and the server isn't reading
 | 
			
		||||
	// The total number of drops should thus be 1 (the socket allows doubling the queue size for no_socket_drop)
 | 
			
		||||
	func (nano::transport::tcp_socket::default_max_queue_size * 2 + 1, nano::transport::buffer_drop_policy::no_socket_drop);
 | 
			
		||||
	ASSERT_EQ (1, node->stats.count (nano::stat::type::tcp, nano::stat::detail::tcp_write_no_socket_drop, nano::stat::dir::out));
 | 
			
		||||
	ASSERT_EQ (0, node->stats.count (nano::stat::type::tcp, nano::stat::detail::tcp_write_drop, nano::stat::dir::out));
 | 
			
		||||
	func (nano::transport::tcp_socket::default_max_queue_size * 2 + 1);
 | 
			
		||||
	ASSERT_EQ (1, failed_writes);
 | 
			
		||||
 | 
			
		||||
	func (nano::transport::tcp_socket::default_max_queue_size + 1, nano::transport::buffer_drop_policy::limiter);
 | 
			
		||||
	// The stats are accumulated from before
 | 
			
		||||
	ASSERT_EQ (1, node->stats.count (nano::stat::type::tcp, nano::stat::detail::tcp_write_no_socket_drop, nano::stat::dir::out));
 | 
			
		||||
	ASSERT_EQ (1, node->stats.count (nano::stat::type::tcp, nano::stat::detail::tcp_write_drop, nano::stat::dir::out));
 | 
			
		||||
	func (nano::transport::tcp_socket::default_max_queue_size + 1);
 | 
			
		||||
	ASSERT_EQ (0, failed_writes);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// This is abusing the socket class, it's interfering with the normal node lifetimes and as a result deadlocks
 | 
			
		||||
| 
						 | 
				
			
			@ -303,7 +305,7 @@ TEST (socket_timeout, connect)
 | 
			
		|||
	// create one node and set timeout to 1 second
 | 
			
		||||
	nano::test::system system (1);
 | 
			
		||||
	std::shared_ptr<nano::node> node = system.nodes[0];
 | 
			
		||||
	node->config.tcp_io_timeout = std::chrono::seconds (1);
 | 
			
		||||
	node->config.tcp_io_timeout = 1s;
 | 
			
		||||
 | 
			
		||||
	// try to connect to an IP address that most likely does not exist and will not reply
 | 
			
		||||
	// we want the tcp stack to not receive a negative reply, we want it to see silence and to keep trying
 | 
			
		||||
| 
						 | 
				
			
			@ -315,22 +317,13 @@ TEST (socket_timeout, connect)
 | 
			
		|||
	std::atomic<bool> done = false;
 | 
			
		||||
	boost::system::error_code ec;
 | 
			
		||||
	socket->async_connect (endpoint, [&ec, &done] (boost::system::error_code const & ec_a) {
 | 
			
		||||
		if (ec_a)
 | 
			
		||||
		{
 | 
			
		||||
			ec = ec_a;
 | 
			
		||||
			done = true;
 | 
			
		||||
		}
 | 
			
		||||
		ec = ec_a;
 | 
			
		||||
		done = true;
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	// check that the callback was called and we got an error
 | 
			
		||||
	// Sometimes the connect will be aborted but there will be no error, just check that the callback was called due to the timeout
 | 
			
		||||
	ASSERT_TIMELY_EQ (6s, done, true);
 | 
			
		||||
	ASSERT_TRUE (ec);
 | 
			
		||||
	ASSERT_EQ (1, node->stats.count (nano::stat::type::tcp, nano::stat::detail::tcp_connect_error, nano::stat::dir::in));
 | 
			
		||||
 | 
			
		||||
	// check that the socket was closed due to tcp_io_timeout timeout
 | 
			
		||||
	// NOTE: this assert is not guaranteed to be always true, it is only likely that it will be true, we can also get "No route to host"
 | 
			
		||||
	// if this test is run repeatedly or in parallel then it is guaranteed to fail due to "No route to host" instead of timeout
 | 
			
		||||
	ASSERT_EQ (1, node->stats.count (nano::stat::type::tcp, nano::stat::detail::tcp_io_timeout_drop, nano::stat::dir::out));
 | 
			
		||||
	ASSERT_TRUE (socket->has_timed_out ());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST (socket_timeout, read)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue