Skip to content

Commit 6716b4e

Browse files
committed
Leader-schedule test helpers no longer depend on where the local node's key sorts
Test-only. The test configuration's node key is derived from the instance number and the day's seed. For a key that sorts behind nearly every other one the helpers could not find a peer that comes after it within their tries (PendingEnvelopes tests: 'could not pick a peer that does not lead round 1'; seen with seed 20769 at base instance 1450, and on the base branch with seed 20768 at 850). createAppWithFollowerPeer now also varies the local key; selectLocalFirstLeader tries more absent peers.
1 parent 90bc094 commit 6716b4e

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎src/herder/test/HerderTests.cpp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5521,7 +5521,11 @@ class LeaderBuildTestAccess
55215521
auto const& lcl = lm.getLastClosedLedgerHeader();
55225522
auto qset = scp.getLocalQuorumSet();
55235523
REQUIRE(qset.validators.size() == 2);
5524-
for (int i = 0; i < 100; ++i)
5524+
// The local node's key is fixed (the instance number and the day's
5525+
// seed decide it) and may sort behind nearly every other key: allow
5526+
// enough candidates for the absent peer to find one that sorts
5527+
// behind even such a key.
5528+
for (int i = 0; i < 2000; ++i)
55255529
{
55265530
qset.validators = {
55275531
scp.getLocalNodeID(),

‎src/herder/test/PendingEnvelopesTests.cpp‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,23 @@ createAppWithFollowerPeer(Config const& baseCfg)
123123
FollowerPeerApp res;
124124
res.mPeer = SecretKey::pseudoRandomForTesting();
125125
Config cfg(baseCfg);
126+
if (i > 0)
127+
{
128+
// A node's place in the leader order is decided by its key. The
129+
// test configuration's key (derived from the instance number and
130+
// the day's seed) can be one that sorts behind nearly every
131+
// other key: no random peer would ever come after it. Try
132+
// another local key as well, not only another peer.
133+
auto const oldKey = cfg.NODE_SEED.getPublicKey();
134+
cfg.NODE_SEED = SecretKey::pseudoRandomForTesting();
135+
for (auto& validator : cfg.QUORUM_SET.validators)
136+
{
137+
if (validator == oldKey)
138+
{
139+
validator = cfg.NODE_SEED.getPublicKey();
140+
}
141+
}
142+
}
126143
cfg.QUORUM_SET.validators.emplace_back(res.mPeer.getPublicKey());
127144
res.mClock = std::make_unique<VirtualClock>();
128145
res.mApp = createTestApplication(*res.mClock, cfg);

0 commit comments

Comments
 (0)