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.

This commit is contained in:
clemahieu 2021-06-13 13:38:28 +02:00
commit 21b0e8d5b4
No known key found for this signature in database
GPG key ID: 43708520C8DFB938
12 changed files with 45 additions and 39 deletions

View file

@ -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<nano::rocksdb_store> (logger, nano::unique_path ());

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -1,3 +1,4 @@
#include <nano/lib/config.hpp>
#include <nano/lib/rocksdbconfig.hpp>
#include <nano/lib/tomlconfig.hpp>
@ -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<int> (use_rocksdb_str) == 1);
}

View file

@ -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 () };

View file

@ -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::block_store> 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<nano::rocksdb_store> (logger, add_db_postfix ? path / "rocksdb" : path, rocksdb_config, read_only);
}

View file

@ -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<int> (use_rocksdb_str) == 1);
}

View file

@ -58,7 +58,5 @@ std::unique_ptr<nano::state_block> upgrade_epoch (nano::work_pool &, nano::ledge
void blocks_confirm (nano::node &, std::vector<std::shared_ptr<nano::block>> 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);

View file

@ -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;

View file

@ -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;

View file

@ -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<nano::block_hash> 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;