Skip to content

Commit e14b4cd

Browse files
committed
Improve quality of soroban metrics test
1 parent 6b02e0d commit e14b4cd

1 file changed

Lines changed: 40 additions & 12 deletions

File tree

src/transactions/test/InvokeHostFunctionTests.cpp

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7647,29 +7647,57 @@ TEST_CASE("soroban metrics published at ledger close", "[soroban]")
76477647
auto const& contract =
76487648
test.deployWasmContract(rust_bridge::get_test_wasm_add_i32());
76497649

7650+
auto minBalance = test.getApp().getLedgerManager().getLastMinBalance(1);
7651+
auto txSourceA = test.getRoot().create("txSourceA", minBalance * 100);
7652+
auto txSourceB = test.getRoot().create("txSourceB", minBalance * 100);
7653+
auto txSourceC = test.getRoot().create("txSourceC", minBalance * 100);
7654+
auto txSourceD = test.getRoot().create("txSourceD", minBalance * 100);
7655+
std::vector<TestAccount*> txSources = {&txSourceA, &txSourceB, &txSourceC,
7656+
&txSourceD};
7657+
76507658
auto& metrics = test.getApp().getLedgerManager().getSorobanMetrics();
76517659
auto preSuccess = metrics.mHostFnOpSuccess.count();
76527660
auto preReadEntry = metrics.mHostFnOpReadEntry.count();
7661+
auto preWriteEntry = metrics.mHostFnOpWriteEntry.count();
76537662
auto preTxSize = metrics.mTxSizeByte.count();
76547663
auto preInvokeTime = metrics.mHostFnOpInvokeTimeNsecs.count();
76557664
auto preExec = metrics.mHostFnOpExec.count();
76567665
auto preTxApply = metrics.mTransactionApply.count();
76577666
auto preOpApply = metrics.mOperationApply.count();
76587667

7659-
auto tx =
7660-
makeAddTx(contract, INVOKE_ADD_UNCACHED_COST_PASS, test.getRoot());
7661-
REQUIRE(isSuccessResult(test.invokeTx(tx)));
7668+
constexpr uint32_t ledgerCount = 3;
7669+
auto const txCountPerLedger = txSources.size();
7670+
for (uint32_t i = 0; i < ledgerCount; ++i)
7671+
{
7672+
std::vector<TransactionFrameBasePtr> txs;
7673+
for (auto* source : txSources)
7674+
{
7675+
txs.emplace_back(
7676+
makeAddTx(contract, INVOKE_ADD_UNCACHED_COST_PASS, *source));
7677+
}
7678+
7679+
ParallelSorobanOrder order = {{{0, 1}, {2, 3}}};
7680+
auto r = closeLedger(test.getApp(), txs, order);
7681+
REQUIRE(r.results.size() == txs.size());
7682+
checkResults(r, txs.size(), 0);
7683+
}
7684+
7685+
auto const appliedTxCount = ledgerCount * txCountPerLedger;
7686+
auto const expectedReadEntries = appliedTxCount * contract.getKeys().size();
76627687

76637688
// Per-op/per-tx metrics recorded during apply are batched per thread and
7664-
// published by the ledger close that applied the tx, so they must all be
7665-
// visible here.
7666-
REQUIRE(metrics.mHostFnOpSuccess.count() == preSuccess + 1);
7667-
REQUIRE(metrics.mHostFnOpReadEntry.count() > preReadEntry);
7668-
REQUIRE(metrics.mTxSizeByte.count() == preTxSize + 1);
7669-
REQUIRE(metrics.mHostFnOpInvokeTimeNsecs.count() == preInvokeTime + 1);
7670-
REQUIRE(metrics.mHostFnOpExec.count() == preExec + 1);
7671-
REQUIRE(metrics.mTransactionApply.count() >= preTxApply + 1);
7672-
REQUIRE(metrics.mOperationApply.count() >= preOpApply + 1);
7689+
// published by the ledger close that applied the tx, so all samples from
7690+
// the parallel apply threads must be visible here.
7691+
REQUIRE(metrics.mHostFnOpSuccess.count() == preSuccess + appliedTxCount);
7692+
REQUIRE(metrics.mHostFnOpReadEntry.count() ==
7693+
preReadEntry + expectedReadEntries);
7694+
REQUIRE(metrics.mHostFnOpWriteEntry.count() == preWriteEntry);
7695+
REQUIRE(metrics.mTxSizeByte.count() == preTxSize + appliedTxCount);
7696+
REQUIRE(metrics.mHostFnOpInvokeTimeNsecs.count() ==
7697+
preInvokeTime + appliedTxCount);
7698+
REQUIRE(metrics.mHostFnOpExec.count() == preExec + appliedTxCount);
7699+
REQUIRE(metrics.mTransactionApply.count() == preTxApply + appliedTxCount);
7700+
REQUIRE(metrics.mOperationApply.count() == preOpApply + appliedTxCount);
76737701
}
76747702

76757703
TEST_CASE("Module cache across protocol versions", "[tx][soroban][modulecache]")

0 commit comments

Comments
 (0)