Skip to content

Commit

Permalink
Merge pull request #3741 from sisuresh/test-fix
Browse files Browse the repository at this point in the history
vnext CONFIG_SETTING test fixes

Reviewed-by: dmkozh
  • Loading branch information
latobarita authored May 22, 2023
2 parents de30daa + 8e5a18f commit 9072cc1
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions src/invariant/test/BucketListIsConsistentWithDatabaseTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ struct BucketListGenerator
key.account().accountID = skey.getPublicKey();
mLiveKeys.insert(key);

#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
// All config settings entries will be created automatically during
// the protocol upgrade and NOT generated by tests, so they should be
// reflected in the live key set. This allows tests to still run on
// those entries.
for (auto t : xdr::xdr_traits<ConfigSettingID>::enum_values())
{
LedgerKey ckey(CONFIG_SETTING);
ckey.configSetting().configSettingID =
static_cast<ConfigSettingID>(t);
mLiveKeys.insert(ckey);
}
#endif

LedgerTxn ltx(mAppGenerate->getLedgerTxnRoot(), false);
REQUIRE(mLedgerSeq == ltx.loadHeader().current().ledgerSeq);
}
Expand Down Expand Up @@ -148,14 +162,23 @@ struct BucketListGenerator
virtual std::vector<LedgerKey>
generateDeadEntries(AbstractLedgerTxn& ltx)
{
UnorderedSet<LedgerKey> live(mLiveKeys);
#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
UnorderedSet<LedgerKey> liveDeletable(mLiveKeys.size());
std::copy_if(mLiveKeys.begin(), mLiveKeys.end(),
std::inserter(liveDeletable, liveDeletable.end()),
[this](LedgerKey const& key) {
return key.type() != CONFIG_SETTING;
});
#else
UnorderedSet<LedgerKey> liveDeletable(mLiveKeys);
#endif
std::vector<LedgerKey> dead;
while (dead.size() < 2 && !live.empty())
while (dead.size() < 2 && !liveDeletable.empty())
{
auto dist =
stellar::uniform_int_distribution<size_t>(0, live.size() - 1);
auto dist = stellar::uniform_int_distribution<size_t>(
0, liveDeletable.size() - 1);
auto index = dist(gRandomEngine);
auto iter = live.begin();
auto iter = liveDeletable.begin();
std::advance(iter, index);
#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
if (iter->type() == CONFIG_SETTING)
Expand All @@ -165,7 +188,7 @@ struct BucketListGenerator
}
#endif
dead.push_back(*iter);
live.erase(iter);
liveDeletable.erase(iter);
}
return dead;
}
Expand Down Expand Up @@ -743,6 +766,14 @@ TEST_CASE("BucketListIsConsistentWithDatabase modified entries",
{
for (auto t : xdr::xdr_traits<LedgerEntryType>::enum_values())
{
#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
// Skip CONFIG_SETTING for now because the test modification test does
// not work unless blg itself updates the entry.
if (t == CONFIG_SETTING)
{
continue;
}
#endif
size_t nTests = 0;
while (nTests < 10)
{
Expand All @@ -752,19 +783,10 @@ TEST_CASE("BucketListIsConsistentWithDatabase modified entries",
{
continue;
}
#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
if (t == CONFIG_SETTING)
{
// Configuration can not be deleted.
REQUIRE_THROWS_AS(blg.applyBuckets<ApplyBucketsWorkDeleteEntry>(
*blg.mSelected),
std::runtime_error);
}
else
#endif
REQUIRE_THROWS_AS(blg.applyBuckets<ApplyBucketsWorkDeleteEntry>(
*blg.mSelected),
InvariantDoesNotHold);

REQUIRE_THROWS_AS(
blg.applyBuckets<ApplyBucketsWorkModifyEntry>(*blg.mSelected),
InvariantDoesNotHold);
++nTests;
}
}
Expand Down

0 comments on commit 9072cc1

Please sign in to comment.