Skip to content

Commit 3c7fb22

Browse files
authored
harden simulation tests (#4423)
* Minor follow up to #4353 to harden tests * Bump medida
2 parents ec3c8e8 + f95961e commit 3c7fb22

File tree

5 files changed

+31
-34
lines changed

5 files changed

+31
-34
lines changed

lib/libmedida

src/overlay/test/OverlayTests.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -2325,12 +2325,13 @@ TEST_CASE("peer is purged from database after few failures",
23252325
REQUIRE(!peerManager.load(localhost(cfg2.PEER_PORT)).second);
23262326
}
23272327

2328-
TEST_CASE("disconnected topology recovery")
2328+
TEST_CASE("disconnected topology recovery", "[overlay][simulation]")
23292329
{
2330+
auto initCfg = getTestConfig();
23302331
auto cfgs = std::vector<Config>{};
23312332
auto peers = std::vector<std::string>{};
23322333

2333-
for (int i = 0; i < 8; ++i)
2334+
for (int i = 0; i < 7; ++i)
23342335
{
23352336
auto cfg = getTestConfig(i + 1);
23362337
cfgs.push_back(cfg);
@@ -2340,8 +2341,12 @@ TEST_CASE("disconnected topology recovery")
23402341
auto doTest = [&](bool usePreferred) {
23412342
auto simulation = Topologies::separate(
23422343
7, 0.5, Simulation::OVER_LOOPBACK,
2343-
sha256(getTestConfig().NETWORK_PASSPHRASE), 0, [&](int i) {
2344-
auto cfg = cfgs[i];
2344+
sha256(initCfg.NETWORK_PASSPHRASE), 0, [&](int i) {
2345+
if (i == 0)
2346+
{
2347+
return initCfg;
2348+
}
2349+
auto cfg = cfgs[i - 1];
23452350
cfg.TARGET_PEER_CONNECTIONS = 1;
23462351
if (usePreferred)
23472352
{

src/overlay/test/SurveyManagerTests.cpp

+14-11
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ setupStaticNetworkTopology(std::vector<Config>& configList,
109109
}
110110

111111
// D->A->B->C B->E
112-
simulation->addConnection(keyList[D], keyList[A]);
113-
simulation->addConnection(keyList[A], keyList[B]);
114-
simulation->addConnection(keyList[B], keyList[C]);
115-
simulation->addConnection(keyList[B], keyList[E]);
112+
simulation->addPendingConnection(keyList[D], keyList[A]);
113+
simulation->addPendingConnection(keyList[A], keyList[B]);
114+
simulation->addPendingConnection(keyList[B], keyList[C]);
115+
simulation->addPendingConnection(keyList[B], keyList[E]);
116116

117117
simulation->startAllNodes();
118118

@@ -402,7 +402,7 @@ TEST_CASE("survey request process order", "[overlay][survey][topology]")
402402
{
403403
for (int j = i + 1; j < numberOfNodes; j++)
404404
{
405-
simulation->addConnection(keyList[i], keyList[j]);
405+
simulation->addPendingConnection(keyList[i], keyList[j]);
406406
}
407407
}
408408

@@ -731,10 +731,10 @@ TEST_CASE("Time sliced dynamic topology survey", "[overlay][survey][topology]")
731731
}
732732

733733
// D->A->B->C B->E (F not connected)
734-
simulation->addConnection(keyList[D], keyList[A]);
735-
simulation->addConnection(keyList[A], keyList[B]);
736-
simulation->addConnection(keyList[B], keyList[C]);
737-
simulation->addConnection(keyList[B], keyList[E]);
734+
simulation->addPendingConnection(keyList[D], keyList[A]);
735+
simulation->addPendingConnection(keyList[A], keyList[B]);
736+
simulation->addPendingConnection(keyList[B], keyList[C]);
737+
simulation->addPendingConnection(keyList[B], keyList[E]);
738738

739739
simulation->startAllNodes();
740740

@@ -785,10 +785,13 @@ TEST_CASE("Time sliced dynamic topology survey", "[overlay][survey][topology]")
785785
checkSurveyState(nonce, /*isReporting*/ false, {A, B, C, D, E});
786786

787787
// Add F to the simulation and connect to B
788-
simulation->addNode(configList.at(F).NODE_SEED, qSet, &configList.at(F));
789-
simulation->getNode(keyList[F])->start();
788+
simulation->addNode(configList.at(F).NODE_SEED, qSet, &configList.at(F))
789+
->start();
790790
simulation->addConnection(keyList[F], keyList[B]);
791791

792+
// Let survey run for a bit to establish connection
793+
crankForSurvey();
794+
792795
// Disconnect E from B
793796
simulation->dropConnection(keyList[B], keyList[E]);
794797

src/simulation/Simulation.cpp

-18
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ Simulation::Simulation(Mode mode, Hash const& networkID, ConfigGen confGen,
4545
parallel = parallel && mVirtualClockMode == VirtualClock::REAL_TIME;
4646
mIdleApp = Application::create(mClock, cfg);
4747
mPeerMap.emplace(mIdleApp->getConfig().PEER_PORT, mIdleApp);
48-
49-
// mIdleApp can end up connected to some nodes in the simulation, but never
50-
// starts Herder. Therefore, it needs to initialize the max tx size so that
51-
// an assertion doesn't fail when it initializes flow control.
52-
Herder& herder = mIdleApp->getHerder();
53-
herder.setMaxTxSize(herder.getMaxClassicTxSize());
5448
}
5549

5650
Simulation::~Simulation()
@@ -152,18 +146,6 @@ Simulation::addNode(SecretKey nodeKey, SCPQuorumSet qSet, Config const* cfg2,
152146

153147
mPeerMap.emplace(app->getConfig().PEER_PORT,
154148
std::weak_ptr<Application>(app));
155-
156-
Herder& herder = app->getHerder();
157-
if (herder.getState() == Herder::HERDER_BOOTING_STATE)
158-
{
159-
// Application creation did not start Herder. To protect against cases
160-
// where the test using this new node run the node's OverlayManager
161-
// without starting Herder, we initialize the max tx size here. This
162-
// prevents an assertion failure on flow control initialization. This is
163-
// harmless if the test later starts Herder as `HerderImpl::start` will
164-
// overwrite this value.
165-
herder.setMaxTxSize(herder.getMaxClassicTxSize());
166-
}
167149
return app;
168150
}
169151

src/simulation/Simulation.h

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class Simulation
4747
void setCurrentVirtualTime(VirtualClock::time_point t);
4848
void setCurrentVirtualTime(VirtualClock::system_time_point t);
4949

50+
// Add new node to the simulation. This function does not start the node.
51+
// Callers are expected to call `start` or `startAllNodes` manually.
5052
Application::pointer addNode(SecretKey nodeKey, SCPQuorumSet qSet,
5153
Config const* cfg = nullptr, bool newDB = true,
5254
uint32_t startAtLedger = 0,
@@ -55,6 +57,9 @@ class Simulation
5557
std::vector<Application::pointer> getNodes();
5658
std::vector<NodeID> getNodeIDs();
5759

60+
// Add a pending connection to an unstarted node. Typically called after
61+
// `addNode`, but before `startAllNodes`. No-op if the simulation is already
62+
// started.
5863
void addPendingConnection(NodeID const& initiator, NodeID const& acceptor);
5964
// Returns LoopbackPeerConnection given initiator, acceptor pair or nullptr
6065
std::shared_ptr<LoopbackPeerConnection>
@@ -80,6 +85,8 @@ class Simulation
8085
void crankUntil(VirtualClock::system_time_point timePoint, bool finalCrank);
8186
std::string metricsSummary(std::string domain = "");
8287

88+
// Add a real (not pending) connection to the simulation. Works even if the
89+
// simulation has started.
8390
void addConnection(NodeID initiator, NodeID acceptor);
8491
void dropConnection(NodeID initiator, NodeID acceptor);
8592
Config newConfig(); // generates a new config

0 commit comments

Comments
 (0)