Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marta-lokhova committed Aug 29, 2024
1 parent 9aad6ed commit 44b62c0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 6 deletions.
25 changes: 25 additions & 0 deletions src/history/test/HistoryTestsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,31 @@ CatchupSimulation::ensurePublishesComplete()
REQUIRE(hm.getPublishFailureCount() == 0);
// Make sure all references to buckets were released
REQUIRE(hm.getBucketsReferencedByPublishQueue().empty());

// Make sure all the checkpoint files have been cleaned up from local
// filesystem Every checkpoiunt file prior to LCL should have been published
// and cleaned up
auto lcl = mApp.getLedgerManager().getLastClosedLedgerNum();
auto firstCheckpoint =
hm.checkpointContainingLedger(LedgerManager::GENESIS_LEDGER_SEQ);
auto lastCheckpoint = hm.lastLedgerBeforeCheckpointContaining(lcl);

for (uint32_t i = firstCheckpoint; i <= lastCheckpoint;
i += hm.getCheckpointFrequency())
{
FileTransferInfo res(FileType::HISTORY_FILE_TYPE_RESULTS, i,
mApp.getConfig());
FileTransferInfo txs(FileType::HISTORY_FILE_TYPE_TRANSACTIONS, i,
mApp.getConfig());
FileTransferInfo headers(FileType::HISTORY_FILE_TYPE_LEDGER, i,
mApp.getConfig());
REQUIRE(!fs::exists(res.localPath_nogz_tmp()));
REQUIRE(!fs::exists(txs.localPath_nogz_tmp()));
REQUIRE(!fs::exists(headers.localPath_nogz_tmp()));
REQUIRE(!fs::exists(res.localPath_nogz()));
REQUIRE(!fs::exists(txs.localPath_nogz()));
REQUIRE(!fs::exists(headers.localPath_nogz()));
}
}

void
Expand Down
52 changes: 48 additions & 4 deletions src/main/test/ApplicationUtilsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ class SimulationHelper

// State has been rebuilt and node is properly in sync
REQUIRE(checkState(*app));
REQUIRE(app->getLedgerManager().getLastClosedLedgerNum() ==
getMainNodeLCL().header.ledgerSeq);
REQUIRE(app->getLedgerManager().getLastClosedLedgerNum() >=
getMainNodeLCL().header.ledgerSeq - 1);
REQUIRE(app->getLedgerManager().isSynced());

if (triggerCatchup)
Expand Down Expand Up @@ -411,6 +411,50 @@ TEST_CASE("Recover publish queue on ledgerClose crash", "[applicationutils]")
simulation.publishCheckpoints(2);
}

TEST_CASE("Truncate checkpoint data on uncommitted ledgers",
"[applicationutils]")
{
// Publish a few checkpoints then shut down test node
auto cfg1 = getTestConfig(1, Config::TESTDB_ON_DISK_SQLITE);
auto cfg2 = getTestConfig(2, Config::TESTDB_ON_DISK_SQLITE);

auto simulation = SimulationHelper(cfg1, cfg2);
auto& hm = static_cast<HistoryManagerImpl&>(
simulation.mMainNode->getHistoryManager());
hm.mThrowOnLastAppend = true;
auto checkpoint = hm.checkpointContainingLedger(1);

REQUIRE_THROWS_AS(simulation.publishCheckpoints(1), std::runtime_error);
simulation.mMainNode.reset();

auto checkLastWrittenLegder = [&](uint32_t expected) {
auto ledgerHeaderFile = FileTransferInfo{
FileType::HISTORY_FILE_TYPE_LEDGER, checkpoint, cfg1};
XDRInputFileStream hdrIn;
hdrIn.open(ledgerHeaderFile.localPath_nogz_tmp());
LedgerHeaderHistoryEntry lcl;
while (hdrIn && hdrIn.readOne(lcl))
{
}
REQUIRE(lcl.header.ledgerSeq == expected);
};

// At this point, LCL should be 6 (applying 7 crashed, but checkpoint files
// were still written)
checkLastWrittenLegder(checkpoint);

simulation.mSimulation->removeNode(simulation.mMainNodeID);
simulation.shutdownTestNode();
simulation.mMainNode = simulation.mSimulation->addNode(
cfg1.NODE_SEED, simulation.mQuorum, &cfg1, false);

REQUIRE(simulation.mMainNode->getLedgerManager().getLastClosedLedgerNum() ==
checkpoint - 1);
simulation.mMainNode->start();
// ledger 7 got truncated on re-start
checkLastWrittenLegder(checkpoint - 1);
}

TEST_CASE("verify checkpoints command - wait condition", "[applicationutils]")
{
auto networkID = sha256(getTestConfig().NETWORK_PASSPHRASE);
Expand Down Expand Up @@ -503,8 +547,8 @@ TEST_CASE("offline self-check works", "[applicationutils][selfcheck]")
{
// Damage the target ledger in the archive.
auto path = archPath;
path /=
fs::remoteName(HISTORY_FILE_TYPE_LEDGER, fs::hexStr(l1), "xdr.gz");
path /= fs::remoteName(typeString(FileType::HISTORY_FILE_TYPE_LEDGER),
fs::hexStr(l1), "xdr.gz");
TemporaryFileDamager damage(path);
damage.damageVictim();
REQUIRE(selfCheck(chkConfig) == 1);
Expand Down
4 changes: 2 additions & 2 deletions src/test/TxTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ closeLedgerOn(Application& app, uint32 ledgerSeq, TimePoint closeTime,
app.getHerder().externalizeValue(txSet.first, ledgerSeq, closeTime,
emptyUpgradeSteps);
REQUIRE(app.getLedgerManager().getLastClosedLedgerNum() == ledgerSeq);
return getTransactionHistoryResults(app.getDatabase(), ledgerSeq);
return getTransactionHistoryResults(ledgerSeq, app);
}

TransactionResultSet
Expand All @@ -568,7 +568,7 @@ closeLedgerOn(Application& app, uint32 ledgerSeq, time_t closeTime,
app.getHerder().externalizeValue(txSet, ledgerSeq, closeTime,
emptyUpgradeSteps);

auto z1 = getTransactionHistoryResults(app.getDatabase(), ledgerSeq);
auto z1 = getTransactionHistoryResults(ledgerSeq, app);

REQUIRE(app.getLedgerManager().getLastClosedLedgerNum() == ledgerSeq);

Expand Down

0 comments on commit 44b62c0

Please sign in to comment.