From ce579bcb8e15770c58948217700d01f66dd7df26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Wed, 18 Sep 2024 12:03:28 +0300 Subject: [PATCH] =?UTF-8?q?mdbx-testing:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20`extra/open`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/CMakeLists.txt | 1 + test/extra/open.c++ | 88 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 test/extra/open.c++ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3296f5a5..697f27fd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -284,6 +284,7 @@ else() add_extra_test(doubtless_positioning TIMEOUT 10800) add_extra_test(crunched_delete TIMEOUT 10800) add_extra_test(dbi) + add_extra_test(open) endif() endif() diff --git a/test/extra/open.c++ b/test/extra/open.c++ new file mode 100644 index 00000000..d475182c --- /dev/null +++ b/test/extra/open.c++ @@ -0,0 +1,88 @@ +#include "mdbx.h++" + +#include + +#if !defined(__cpp_lib_latch) && __cpp_lib_latch < 201907L + +int main(int argc, const char *argv[]) { + (void)argc; + (void)argv; + std::cout << "FAKE-OK (since no C++20 std::thread and/or std::latch\n"; + return EXIT_SUCCESS; +} + +#else + +#include +#include + +static char log_buffer[1024]; + +static void logger_nofmt(MDBX_log_level_t loglevel, const char *function, + int line, const char *msg, unsigned length) noexcept { + (void)length; + (void)loglevel; + fprintf(stdout, "%s:%u %s", function, line, msg); +} + +int main(int argc, const char *argv[]) { + (void)argc; + (void)argv; + + mdbx_setup_debug_nofmt(MDBX_LOG_VERBOSE, MDBX_DBG_ASSERT, logger_nofmt, + log_buffer, sizeof(log_buffer)); + + mdbx::path path = "test-open"; + mdbx::env::remove(path); + + { + mdbx::env::operate_parameters operateParameters2(100, 10); + mdbx::env_managed::create_parameters createParameters2; + createParameters2.geometry.make_fixed(42 * mdbx::env::geometry::MiB); + mdbx::env_managed env2(path, createParameters2, operateParameters2); + mdbx::txn_managed txn2 = env2.start_write(false); + /* mdbx::map_handle testHandle2 = */ txn2.create_map( + "fap1", mdbx::key_mode::reverse, mdbx::value_mode::single); + txn2.commit(); + } + + mdbx::env::operate_parameters operateParameters(100, 10); + mdbx::env_managed::create_parameters createParameters; + createParameters.geometry.make_dynamic(21 * mdbx::env::geometry::MiB, + 84 * mdbx::env::geometry::MiB); + mdbx::env_managed env(path, createParameters, operateParameters); + mdbx::txn_managed txn = env.start_write(false); + /* mdbx::map_handle testHandle = */ txn.create_map( + "fap1", mdbx::key_mode::usual, mdbx::value_mode::single); + txn.commit(); + + std::latch starter(1); + + std::thread t1([&]() { + starter.wait(); + // mdbx::env_managed env(path, createParameters, operateParameters); + mdbx::txn_managed txn = env.start_write(false); + /* mdbx::map_handle testHandle = */ txn.create_map( + "fap1", mdbx::key_mode::usual, mdbx::value_mode::single); + txn.commit(); + }); + + std::thread t2([&]() { + starter.wait(); + // mdbx::env_managed env(path, createParameters, operateParameters); + mdbx::txn_managed txn = env.start_write(false); + /* mdbx::map_handle testHandle = */ txn.create_map( + "fap1", mdbx::key_mode::usual, mdbx::value_mode::single); + txn.commit(); + }); + + starter.count_down(); + + t1.join(); + t2.join(); + + std::cout << "OK\n"; + return EXIT_SUCCESS; +} + +#endif /* __cpp_lib_latch */