Skip to content

Commit

Permalink
Fix(?) the DatabaseShard manual test timing
Browse files Browse the repository at this point in the history
This fix has been included in XRPLF#3875, so watch out for merge conflicts
  • Loading branch information
ximinez committed Sep 15, 2021
1 parent b1865c0 commit 7c25e6d
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/test/nodestore/DatabaseShard_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/app/ledger/LedgerToJson.h>
#include <ripple/app/misc/LoadFeeTrack.h>
#include <ripple/app/misc/SHAMapStore.h>
#include <ripple/app/rdb/backend/RelationalDBInterfaceSqlite.h>
#include <ripple/basics/Slice.h>
Expand Down Expand Up @@ -263,6 +264,10 @@ class DatabaseShard_test : public TestBase
{
using namespace test::jtx;

// The local fee may go up, especially in the online delete tests
while (env_.app().getFeeTrack().lowerLocalFee())
std::this_thread::sleep_for(std::chrono::milliseconds(1));

if (isNewAccounts(seq))
env_.fund(XRP(iniAmount), accounts_[nAccounts_[seq] - 1]);

Expand Down Expand Up @@ -1249,14 +1254,22 @@ class DatabaseShard_test : public TestBase
Database& ndb = env.app().getNodeStore();
BEAST_EXPECT(db);

auto& store = env.app().getSHAMapStore();

// Allow online delete to delete the startup ledgers
// so that it will take some time for the import to
// catch up to the point of the next rotation
store.setCanDelete(10);

// Create some ledgers for the shard store to import
auto const shardCount = 5;
TestData data(seedValue, 4, shardCount);
if (!BEAST_EXPECT(data.makeLedgers(env)))
return;

auto& store = env.app().getSHAMapStore();
auto lastRotated = store.getLastRotated();
store.rendezvous();
auto const lastRotated = store.getLastRotated();
BEAST_EXPECT(lastRotated >= 553 && lastRotated < 1103);

// Start the import
db->importDatabase(ndb);
Expand All @@ -1267,24 +1280,27 @@ class DatabaseShard_test : public TestBase
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}

// Enable online deletion now that the import has started
// Enable unimpeded online deletion now that the import has started
store.setCanDelete(std::numeric_limits<std::uint32_t>::max());

auto pauseVerifier = std::thread([lastRotated, &store, db, this] {
while (true)
// The import should still be running when this thread starts
BEAST_EXPECT(db->getDatabaseImportSequence());
auto rotationProgress = lastRotated;
while (auto const ledgerSeq = db->getDatabaseImportSequence())
{
// Make sure database rotations dont interfere
// with the import

if (store.getLastRotated() != lastRotated)
auto const last = store.getLastRotated();
if (last != rotationProgress)
{
// A rotation occurred during shard import. Not
// necessarily an error

auto const ledgerSeq = db->getDatabaseImportSequence();
BEAST_EXPECT(!ledgerSeq || ledgerSeq >= lastRotated);

break;
BEAST_EXPECT(
!ledgerSeq || ledgerSeq >= rotationProgress);
rotationProgress = last;
}
}
});
Expand Down

0 comments on commit 7c25e6d

Please sign in to comment.