Skip to content

Commit

Permalink
Merge bitcoin#8070: Remove non-determinism which is breaking net_tests
Browse files Browse the repository at this point in the history
…bitcoin#8069

2a8b358 Fix typo adddrman to addrman as requested in bitcoin#8070 (Ethan Heilman)
f4119c6 Remove non-determinism which is breaking net_tests bitcoin#8069 (EthanHeilman)
  • Loading branch information
laanwj committed May 19, 2016
2 parents 18436d8 + 2a8b358 commit 7771aa5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/test/net_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ class CAddrManSerializationMock : public CAddrMan
{
public:
virtual void Serialize(CDataStream& s, int nType, int nVersionDummy) const = 0;

//! Ensure that bucket placement is always the same for testing purposes.
void MakeDeterministic()
{
nKey.SetNull();
seed_insecure_rand(true);
}
};

class CAddrManUncorrupted : public CAddrManSerializationMock
Expand Down Expand Up @@ -65,6 +72,7 @@ BOOST_FIXTURE_TEST_SUITE(net_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(caddrdb_read)
{
CAddrManUncorrupted addrmanUncorrupted;
addrmanUncorrupted.MakeDeterministic();

CService addr1 = CService("250.7.1.1", 8333);
CService addr2 = CService("250.7.2.2", 9999);
Expand Down Expand Up @@ -106,6 +114,7 @@ BOOST_AUTO_TEST_CASE(caddrdb_read)
BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted)
{
CAddrManCorrupted addrmanCorrupted;
addrmanCorrupted.MakeDeterministic();

// Test that the de-serialization of corrupted addrman throws an exception.
CDataStream ssPeers1 = AddrmanToStream(addrmanCorrupted);
Expand All @@ -119,7 +128,7 @@ BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted)
} catch (const std::exception& e) {
exceptionThrown = true;
}
// Even through de-serialization failed adddrman is not left in a clean state.
// Even through de-serialization failed addrman is not left in a clean state.
BOOST_CHECK(addrman1.size() == 1);
BOOST_CHECK(exceptionThrown);

Expand Down

0 comments on commit 7771aa5

Please sign in to comment.