Skip to content

Commit 7771aa5

Browse files
committed
Merge #8070: Remove non-determinism which is breaking net_tests #8069
2a8b358 Fix typo adddrman to addrman as requested in #8070 (Ethan Heilman) f4119c6 Remove non-determinism which is breaking net_tests #8069 (EthanHeilman)
2 parents 18436d8 + 2a8b358 commit 7771aa5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/test/net_tests.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ class CAddrManSerializationMock : public CAddrMan
1717
{
1818
public:
1919
virtual void Serialize(CDataStream& s, int nType, int nVersionDummy) const = 0;
20+
21+
//! Ensure that bucket placement is always the same for testing purposes.
22+
void MakeDeterministic()
23+
{
24+
nKey.SetNull();
25+
seed_insecure_rand(true);
26+
}
2027
};
2128

2229
class CAddrManUncorrupted : public CAddrManSerializationMock
@@ -65,6 +72,7 @@ BOOST_FIXTURE_TEST_SUITE(net_tests, BasicTestingSetup)
6572
BOOST_AUTO_TEST_CASE(caddrdb_read)
6673
{
6774
CAddrManUncorrupted addrmanUncorrupted;
75+
addrmanUncorrupted.MakeDeterministic();
6876

6977
CService addr1 = CService("250.7.1.1", 8333);
7078
CService addr2 = CService("250.7.2.2", 9999);
@@ -106,6 +114,7 @@ BOOST_AUTO_TEST_CASE(caddrdb_read)
106114
BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted)
107115
{
108116
CAddrManCorrupted addrmanCorrupted;
117+
addrmanCorrupted.MakeDeterministic();
109118

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

0 commit comments

Comments
 (0)