Skip to content

Commit

Permalink
Add CConnmanTest to mutate g_connman in tests
Browse files Browse the repository at this point in the history
Github-Pull: bitcoin#11560
Rebased-From: 83df257
  • Loading branch information
promag authored and MarcoFalke committed Nov 2, 2017
1 parent a607a95 commit 2ed0647
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ class CConnman
* in excess of nMaxOutbound
* This takes the place of a feeler connection */
std::atomic_bool m_try_another_outbound_peer;

friend struct CConnmanTest;
};
extern std::unique_ptr<CConnman> g_connman;
void Discover(boost::thread_group& threadGroup);
Expand Down
12 changes: 12 additions & 0 deletions src/test/test_bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@

#include <memory>

void CConnmanTest::AddNode(CNode& node)
{
LOCK(g_connman->cs_vNodes);
g_connman->vNodes.push_back(&node);
}

void CConnmanTest::ClearNodes()
{
LOCK(g_connman->cs_vNodes);
g_connman->vNodes.clear();
}

uint256 insecure_rand_seed = GetRandHash();
FastRandomContext insecure_rand_ctx(insecure_rand_seed);

Expand Down
6 changes: 6 additions & 0 deletions src/test/test_bitcoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ struct BasicTestingSetup {
* Included are data directory, coins database, script check threads setup.
*/
class CConnman;
class CNode;
struct CConnmanTest {
static void AddNode(CNode& node);
static void ClearNodes();
};

class PeerLogicValidation;
struct TestingSetup: public BasicTestingSetup {
CCoinsViewDB *pcoinsdbview;
Expand Down

0 comments on commit 2ed0647

Please sign in to comment.