Creates unittests for addrman, makes addrman testable.

Adds several unittests for addrman to verify it works as expected.
Makes small modifications to addrman to allow deterministic and targeted tests.

Signed-off-by: Simon <simon@bitcartel.com>
This commit is contained in:
EthanHeilman
2015-09-22 15:24:16 -04:00
committed by Simon
parent b0f75847ea
commit 8375e1a3e7
4 changed files with 199 additions and 6 deletions

View File

@@ -22,6 +22,8 @@
*/
class CAddrInfo : public CAddress
{
public:
//! last try whatsoever by us (memory only)
int64_t nLastTry;
@@ -230,8 +232,8 @@ protected:
//! Mark an entry as attempted to connect.
void Attempt_(const CService &addr, int64_t nTime);
//! Select an address to connect to.
CAddrInfo Select_();
//! Select an address to connect to, if newOnly is set to true, only the new table is selected from.
CAddrInfo Select_(bool newOnly);
#ifdef DEBUG_ADDRMAN
//! Perform consistency check. Returns an error code or zero.
@@ -532,13 +534,13 @@ public:
/**
* Choose an address to connect to.
*/
CAddrInfo Select()
CAddrInfo Select(bool newOnly = false)
{
CAddrInfo addrRet;
{
LOCK(cs);
Check();
addrRet = Select_();
addrRet = Select_(newOnly);
Check();
}
return addrRet;
@@ -567,6 +569,12 @@ public:
Check();
}
}
//! Ensure that bucket placement is always the same for testing purposes.
void MakeDeterministic(){
nKey.SetNull(); //Do not use outside of tests.
}
};
#endif // BITCOIN_ADDRMAN_H