From 21b0e8d5b4182936dc0b579d249abeeafc55146f Mon Sep 17 00:00:00 2001 From: clemahieu Date: Sun, 13 Jun 2021 13:38:28 +0200 Subject: [PATCH] Moving the check "using_rocksdb_in_tests" on to rocksdb_config, which is logically where it belongs. Also this moves the check from the node library in to the nano_lib library. This addresses a circular reference where node code is referencing the test library. --- nano/core_test/block_store.cpp | 30 +++++++++++++------------- nano/core_test/confirmation_height.cpp | 8 +++---- nano/core_test/ledger.cpp | 2 +- nano/core_test/node.cpp | 4 ++-- nano/lib/rocksdbconfig.cpp | 8 +++++++ nano/lib/rocksdbconfig.hpp | 7 ++++++ nano/node/node.cpp | 4 ++-- nano/node/testing.cpp | 7 ------ nano/node/testing.hpp | 2 -- nano/qt_test/qt.cpp | 4 ++-- nano/rpc_test/rpc.cpp | 2 +- nano/slow_test/node.cpp | 6 +++--- 12 files changed, 45 insertions(+), 39 deletions(-) diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 0dbf306c..7f6c857e 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -369,7 +369,7 @@ TEST (bootstrap, simple) TEST (unchecked, multiple) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -654,7 +654,7 @@ TEST (block_store, latest_find) TEST (mdb_block_store, supported_version_upgrades) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -705,7 +705,7 @@ TEST (mdb_block_store, supported_version_upgrades) TEST (mdb_block_store, bad_path) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -999,7 +999,7 @@ TEST (block_store, state_block) TEST (mdb_block_store, sideband_height) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -1264,7 +1264,7 @@ TEST (block_store, pruned_blocks) TEST (mdb_block_store, upgrade_v14_v15) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -1377,7 +1377,7 @@ TEST (mdb_block_store, upgrade_v14_v15) TEST (mdb_block_store, upgrade_v15_v16) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -1423,7 +1423,7 @@ TEST (mdb_block_store, upgrade_v15_v16) TEST (mdb_block_store, upgrade_v16_v17) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -1487,7 +1487,7 @@ TEST (mdb_block_store, upgrade_v16_v17) TEST (mdb_block_store, upgrade_v17_v18) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -1691,7 +1691,7 @@ TEST (mdb_block_store, upgrade_v17_v18) TEST (mdb_block_store, upgrade_v18_v19) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -1784,7 +1784,7 @@ TEST (mdb_block_store, upgrade_v18_v19) TEST (mdb_block_store, upgrade_v19_v20) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -1814,7 +1814,7 @@ TEST (mdb_block_store, upgrade_v19_v20) TEST (mdb_block_store, upgrade_v20_v21) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -1844,7 +1844,7 @@ TEST (mdb_block_store, upgrade_v20_v21) TEST (mdb_block_store, upgrade_backup) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -1886,7 +1886,7 @@ TEST (mdb_block_store, upgrade_backup) // Test various confirmation height values as well as clearing them TEST (block_store, confirmation_height) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -1932,7 +1932,7 @@ TEST (block_store, confirmation_height) // Test various confirmation height values as well as clearing them TEST (block_store, final_vote) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode as deletions cause inaccurate counts return; @@ -2041,7 +2041,7 @@ namespace nano { TEST (rocksdb_block_store, tombstone_count) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { nano::logger_mt logger; auto store = std::make_unique (logger, nano::unique_path ()); diff --git a/nano/core_test/confirmation_height.cpp b/nano/core_test/confirmation_height.cpp index 04be4cc0..311e7646 100644 --- a/nano/core_test/confirmation_height.cpp +++ b/nano/core_test/confirmation_height.cpp @@ -707,7 +707,7 @@ TEST (confirmation_height, conflict_rollback_cemented) TEST (confirmation_heightDeathTest, rollback_added_block) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -784,7 +784,7 @@ TEST (confirmation_height, observers) // This tests when a read has been done, but the block no longer exists by the time a write is done TEST (confirmation_heightDeathTest, modified_chain) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -855,7 +855,7 @@ TEST (confirmation_heightDeathTest, modified_chain) // This tests when a read has been done, but the account no longer exists by the time a write is done TEST (confirmation_heightDeathTest, modified_chain_account_removed) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -1355,7 +1355,7 @@ TEST (confirmation_height, election_winner_details_clearing_node_process_confirm TEST (confirmation_height, unbounded_block_cache_iteration) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 9cda4e93..df136786 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -12,7 +12,7 @@ using namespace std::chrono_literals; // Init returns an error if it can't open files at the path TEST (ledger, store_error) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index a2591d30..47d6c853 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -73,7 +73,7 @@ TEST (node_DeathTest, readonly_block_store_not_exist) #endif { // This is a read-only node with no ledger file - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { nano::inactive_node node (nano::unique_path (), nano::inactive_node_flag_defaults ()); ASSERT_TRUE (node.node->init_error ()); @@ -3748,7 +3748,7 @@ TEST (node, dont_write_lock_node) TEST (node, bidirectional_tcp) { #ifdef _WIN32 - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; diff --git a/nano/lib/rocksdbconfig.cpp b/nano/lib/rocksdbconfig.cpp index fb090ca4..c3bac1f2 100644 --- a/nano/lib/rocksdbconfig.cpp +++ b/nano/lib/rocksdbconfig.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -27,3 +28,10 @@ nano::error nano::rocksdb_config::deserialize_toml (nano::tomlconfig & toml) return toml.get_error (); } + +bool nano::rocksdb_config::using_rocksdb_in_tests () +{ + static nano::network_constants network_constants; + auto use_rocksdb_str = std::getenv ("TEST_USE_ROCKSDB"); + return network_constants.is_dev_network () && use_rocksdb_str && (boost::lexical_cast (use_rocksdb_str) == 1); +} diff --git a/nano/lib/rocksdbconfig.hpp b/nano/lib/rocksdbconfig.hpp index 750eab9d..ff185ada 100644 --- a/nano/lib/rocksdbconfig.hpp +++ b/nano/lib/rocksdbconfig.hpp @@ -12,9 +12,16 @@ class tomlconfig; class rocksdb_config final { public: + rocksdb_config () : + enable{ using_rocksdb_in_tests () } + { + } nano::error serialize_toml (nano::tomlconfig & toml_a) const; nano::error deserialize_toml (nano::tomlconfig & toml_a); + /** To use RocksDB in tests make sure the environment variable TEST_USE_ROCKSDB=1 is set */ + static bool using_rocksdb_in_tests (); + bool enable{ false }; uint8_t memory_multiplier{ 2 }; unsigned io_threads{ std::thread::hardware_concurrency () }; diff --git a/nano/node/node.cpp b/nano/node/node.cpp index e8948808..79ce1bef 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -85,7 +85,7 @@ nano::node::node (boost::asio::io_context & io_ctx_a, uint16_t peering_port_a, b } nano::node::node (boost::asio::io_context & io_ctx_a, boost::filesystem::path const & application_path_a, nano::node_config const & config_a, nano::work_pool & work_a, nano::node_flags flags_a, unsigned seq) : - write_database_queue (!flags_a.force_use_write_database_queue && (config_a.rocksdb_config.enable || nano::using_rocksdb_in_tests ())), + write_database_queue (!flags_a.force_use_write_database_queue && (config_a.rocksdb_config.enable)), io_ctx (io_ctx_a), node_initialized_latch (1), config (config_a), @@ -1821,7 +1821,7 @@ nano::node_flags const & nano::inactive_node_flag_defaults () std::unique_ptr nano::make_store (nano::logger_mt & logger, boost::filesystem::path const & path, bool read_only, bool add_db_postfix, nano::rocksdb_config const & rocksdb_config, nano::txn_tracking_config const & txn_tracking_config_a, std::chrono::milliseconds block_processor_batch_max_time_a, nano::lmdb_config const & lmdb_config_a, bool backup_before_upgrade) { - if (rocksdb_config.enable || using_rocksdb_in_tests ()) + if (rocksdb_config.enable) { return std::make_unique (logger, add_db_postfix ? path / "rocksdb" : path, rocksdb_config, read_only); } diff --git a/nano/node/testing.cpp b/nano/node/testing.cpp index 053c74a9..d481bf80 100644 --- a/nano/node/testing.cpp +++ b/nano/node/testing.cpp @@ -550,10 +550,3 @@ void nano::cleanup_dev_directories_on_exit () nano::remove_temporary_directories (); } } - -bool nano::using_rocksdb_in_tests () -{ - static nano::network_constants network_constants; - auto use_rocksdb_str = std::getenv ("TEST_USE_ROCKSDB"); - return network_constants.is_dev_network () && use_rocksdb_str && (boost::lexical_cast (use_rocksdb_str) == 1); -} diff --git a/nano/node/testing.hpp b/nano/node/testing.hpp index aefb36e6..e1f2cbc0 100644 --- a/nano/node/testing.hpp +++ b/nano/node/testing.hpp @@ -58,7 +58,5 @@ std::unique_ptr upgrade_epoch (nano::work_pool &, nano::ledge void blocks_confirm (nano::node &, std::vector> const &, bool const = false); uint16_t get_available_port (); void cleanup_dev_directories_on_exit (); -/** To use RocksDB in tests make sure the environment variable TEST_USE_ROCKSDB=1 is set */ -bool using_rocksdb_in_tests (); } REGISTER_ERROR_CODES (nano, error_system); diff --git a/nano/qt_test/qt.cpp b/nano/qt_test/qt.cpp index 58c650da..a3ee579a 100644 --- a/nano/qt_test/qt.cpp +++ b/nano/qt_test/qt.cpp @@ -498,7 +498,7 @@ TEST (wallet, create_change) TEST (history, short_text) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; @@ -536,7 +536,7 @@ TEST (history, short_text) TEST (history, pruned_source) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index da8fe13b..4cf433e9 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -6839,7 +6839,7 @@ TEST (rpc, block_confirmed) TEST (rpc, database_txn_tracker) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return; diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 51d91974..9214c79a 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -421,7 +421,7 @@ TEST (store, pruned_load) nano::logger_mt logger; auto path (nano::unique_path ()); constexpr auto num_pruned = 2000000; - auto const expected_result = nano::using_rocksdb_in_tests () ? num_pruned : num_pruned / 2; + auto const expected_result = nano::rocksdb_config::using_rocksdb_in_tests () ? num_pruned : num_pruned / 2; constexpr auto batch_size = 20; boost::unordered_set hashes; { @@ -438,7 +438,7 @@ TEST (store, pruned_load) store->pruned.put (transaction, random_hash); } } - if (!nano::using_rocksdb_in_tests ()) + if (!nano::rocksdb_config::using_rocksdb_in_tests ()) { auto transaction (store->tx_begin_write ()); for (auto k (0); k < batch_size / 2; ++k) @@ -956,7 +956,7 @@ TEST (confirmation_height, many_accounts_send_receive_self) // as opposed to active transactions which implicitly calls confirmation height processor. TEST (confirmation_height, many_accounts_send_receive_self_no_elections) { - if (nano::using_rocksdb_in_tests ()) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { // Don't test this in rocksdb mode return;