helium / blockchain-core

Apache License 2.0
213 stars 85 forks source link

Identify connected nodes instead of forcing connections. #1337

Closed marcsugiyama closed 2 years ago

marcsugiyama commented 2 years ago

Many tests randomly fail to run when blockchain_state_channel_SUITE:init_per_testcase/2 fails. init_per_testcase tries to make sure the first two nodes set up by blockchain_ct_utils:init_per_testcase/2, the ?config(nodes, Config) value, are connected to each other as many tests expect this. If the two nodes are not connected to each other, blockchain_state_channel_SUITE:init_per_testcase tries to force a connection. The set up code uses ct_rpc:call(Node, blockchain_swarm, gossip_peers, [], 500) to see if a node is connected to another node and ct_rpc:call(Node, libp2p_swarm, connect, [Swarm, libp2p_crypto:pubkey_bin_to_p2p(AddrToConnectToo)], 500) to force a connection. Even if libp2p_swarm:connect succeeds, it's not clear that the gossip_peers returns the new connection. As a result, the setup always fails if the first to nodes are not connected.

Rather than change how setup forces a connection, this PR inspects the list of nodes and finds two nodes that are connected to each other for the tests to use.

For better clarity, the router and gateway nodes are added explicitly to Config. Also, a new config is added for a connected pair of nodes.

With these changes, all tests in blockchain_state_channel_SUITE are consistently running, however, not all tests are passing consistently. Getting all the tests to pass can be addressed in other PRs.