From a6d7d1ce6669b9f966602e528c884bf3d29b89d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:53:36 +0100 Subject: [PATCH] Test multithreaded transactions --- nano/core_test/ledger.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 0cb99f9a76..cbeab2c29e 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -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 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 (); + } +} \ No newline at end of file