Skip to content

Commit

Permalink
Test multithreaded transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 4, 2024
1 parent 68d6c44 commit a6d7d1c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5861,3 +5861,38 @@ TEST (ledger_transaction, write_wait_order)
// Signal to continue and drop the third transaction
latch3.count_down ();
}

TEST (ledger_transaction, multithreaded_interleaving)
{
nano::test::system system;

auto ctx = nano::test::ledger_empty ();

int constexpr num_threads = 2;
int constexpr num_iterations = 10;
int constexpr num_blocks = 10;

std::deque<std::thread> threads;
for (int i = 0; i < num_threads; ++i)
{
threads.emplace_back ([&] {
for (int n = 0; n < num_iterations; ++n)
{
auto tx = ctx.ledger ().tx_begin_write (nano::store::writer::testing);
for (unsigned k = 0; k < num_blocks; ++k)
{
ctx.store ().account.put (tx, nano::account{ k }, nano::account_info{});
}
for (unsigned k = 0; k < num_blocks; ++k)
{
ctx.store ().account.del (tx, nano::account{ k });
}
}
});
}

for (auto & thread : threads)
{
thread.join ();
}
}

0 comments on commit a6d7d1c

Please sign in to comment.