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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user