local-cluster: tests/common/mod.rs -> src/test.rs (#32821)

Putting code into `tests` does not match the testing layout set by
cargo.  Details in `src/intergation_tests.rs`.
This commit is contained in:
Illia Bobyr 2023-08-14 17:08:16 -07:00 committed by GitHub
parent 52616cf7aa
commit 21c6ac61ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 13 deletions

1
Cargo.lock generated
View File

@ -6350,6 +6350,7 @@ dependencies = [
"solana-tpu-client",
"solana-turbine",
"solana-vote-program",
"static_assertions",
"tempfile",
"trees",
]

View File

@ -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"]

View File

@ -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<C>(
stakes_to_kill: &[(usize, usize)],
alive_stakes: &[(usize, usize)],
@ -175,7 +185,7 @@ pub fn run_kill_partition_switch_threshold<C>(
) {
// 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

View File

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

View File

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