diff --git a/Cargo.lock b/Cargo.lock index 294ec8bd7..d317c6cea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6350,6 +6350,7 @@ dependencies = [ "solana-tpu-client", "solana-turbine", "solana-vote-program", + "static_assertions", "tempfile", "trees", ] diff --git a/local-cluster/Cargo.toml b/local-cluster/Cargo.toml index 9c7fc6330..5f0a3eeae 100644 --- a/local-cluster/Cargo.toml +++ b/local-cluster/Cargo.toml @@ -22,6 +22,7 @@ solana-core = { workspace = true } solana-entry = { workspace = true } solana-gossip = { workspace = true } solana-ledger = { workspace = true } +solana-logger = { workspace = true } solana-pubsub-client = { workspace = true } solana-rpc-client = { workspace = true } solana-rpc-client-api = { workspace = true } @@ -33,6 +34,7 @@ solana-thin-client = { workspace = true } solana-tpu-client = { workspace = true } solana-turbine = { workspace = true } solana-vote-program = { workspace = true } +static_assertions = { workspace = true } tempfile = { workspace = true } trees = { workspace = true } @@ -43,7 +45,6 @@ gag = { workspace = true } serial_test = { workspace = true } solana-download-utils = { workspace = true } solana-ledger = { workspace = true, features = ["dev-context-only-utils"] } -solana-logger = { workspace = true } [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/local-cluster/tests/common/mod.rs b/local-cluster/src/integration_tests.rs similarity index 96% rename from local-cluster/tests/common/mod.rs rename to local-cluster/src/integration_tests.rs index 03e87ccd9..e7691bc1c 100644 --- a/local-cluster/tests/common/mod.rs +++ b/local-cluster/src/integration_tests.rs @@ -1,5 +1,21 @@ -#![allow(clippy::integer_arithmetic)] +//! Code used by the integration tests in the `local-cluster/tests` folder. +//! +//! According to the cargo documentation, integration tests are compiled as individual crates. +//! +//! https://doc.rust-lang.org/book/ch11-03-test-organization.html#the-tests-directory +//! +//! Putting shared code into the `tests/` folder, causes it to be recompiled for every test, rather +//! than being compiled once when it is part of the main crate. And, at the same time, unused code +//! analysis is broken, as it is literally included. If a shared function is not used in one of the +//! integration tests, it will be flagged as unused, when compiling this test crate. + use { + crate::{ + cluster::{Cluster, ClusterValidatorInfo}, + cluster_tests, + local_cluster::{ClusterConfig, LocalCluster}, + validator_configs::*, + }, log::*, solana_accounts_db::accounts_db::create_accounts_run_and_snapshot_dirs, solana_core::{ @@ -13,12 +29,6 @@ use { blockstore_options::{AccessType, BlockstoreOptions}, leader_schedule::{FixedSchedule, LeaderSchedule}, }, - solana_local_cluster::{ - cluster::{Cluster, ClusterValidatorInfo}, - cluster_tests, - local_cluster::{ClusterConfig, LocalCluster}, - validator_configs::*, - }, solana_rpc_client::rpc_client::RpcClient, solana_runtime::{ snapshot_bank_utils::DISABLED_SNAPSHOT_ARCHIVE_INTERVAL, snapshot_config::SnapshotConfig, @@ -33,6 +43,7 @@ use { }, solana_streamer::socket::SocketAddrSpace, solana_turbine::broadcast_stage::BroadcastStageType, + static_assertions, std::{ collections::HashSet, fs, iter, @@ -163,7 +174,6 @@ pub fn ms_for_n_slots(num_blocks: u64, ticks_per_slot: u64) -> u64 { / DEFAULT_TICKS_PER_SLOT } -#[allow(clippy::assertions_on_constants)] pub fn run_kill_partition_switch_threshold( stakes_to_kill: &[(usize, usize)], alive_stakes: &[(usize, usize)], @@ -175,7 +185,7 @@ pub fn run_kill_partition_switch_threshold( ) { // Needs to be at least 1/3 or there will be no overlap // with the confirmation supermajority 2/3 - assert!(SWITCH_FORK_THRESHOLD >= 1f64 / 3f64); + static_assertions::const_assert!(SWITCH_FORK_THRESHOLD >= 1f64 / 3f64); info!( "stakes_to_kill: {:?}, alive_stakes: {:?}", stakes_to_kill, alive_stakes diff --git a/local-cluster/src/lib.rs b/local-cluster/src/lib.rs index dc04bcbe9..65c657875 100644 --- a/local-cluster/src/lib.rs +++ b/local-cluster/src/lib.rs @@ -1,6 +1,7 @@ #![allow(clippy::integer_arithmetic)] pub mod cluster; pub mod cluster_tests; +pub mod integration_tests; pub mod local_cluster; mod local_cluster_snapshot_utils; pub mod validator_configs; diff --git a/local-cluster/tests/local_cluster.rs b/local-cluster/tests/local_cluster.rs index 088508253..b23ac74f7 100644 --- a/local-cluster/tests/local_cluster.rs +++ b/local-cluster/tests/local_cluster.rs @@ -1,7 +1,6 @@ #![allow(clippy::integer_arithmetic)] use { assert_matches::assert_matches, - common::*, crossbeam_channel::{unbounded, Receiver}, gag::BufferRedirect, log::*, @@ -34,6 +33,16 @@ use { solana_local_cluster::{ cluster::{Cluster, ClusterValidatorInfo}, cluster_tests, + integration_tests::{ + copy_blocks, create_custom_leader_schedule, + create_custom_leader_schedule_with_random_keys, farf_dir, generate_account_paths, + last_root_in_tower, last_vote_in_tower, ms_for_n_slots, open_blockstore, + purge_slots_with_count, remove_tower, remove_tower_if_exists, restore_tower, + run_cluster_partition, run_kill_partition_switch_threshold, save_tower, + setup_snapshot_validator_config, test_faulty_node, + wait_for_last_vote_in_tower_to_land_in_ledger, SnapshotValidatorConfig, + ValidatorTestConfig, DEFAULT_CLUSTER_LAMPORTS, DEFAULT_NODE_STAKE, RUST_LOG_FILTER, + }, local_cluster::{ClusterConfig, LocalCluster}, validator_configs::*, }, @@ -92,8 +101,6 @@ use { }, }; -mod common; - #[test] fn test_local_cluster_start_and_exit() { solana_logger::setup();