From 3a4018cd03f6bf37f114d4039473458f28c461d0 Mon Sep 17 00:00:00 2001 From: Anatoly Yakovenko Date: Mon, 4 Mar 2019 09:59:36 -0800 Subject: [PATCH] review comments; rename Unsafe to TestOnlyAllowRpcFullnodeExit --- core/src/local_cluster.rs | 19 ++++++++----------- core/src/rpc.rs | 25 ++++++++++++------------- tests/local_cluster.rs | 6 +++++- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/core/src/local_cluster.rs b/core/src/local_cluster.rs index 7eb53a34fc..9639e3919c 100644 --- a/core/src/local_cluster.rs +++ b/core/src/local_cluster.rs @@ -3,7 +3,6 @@ use crate::client::mk_client; use crate::cluster_info::{Node, NodeInfo}; use crate::fullnode::{Fullnode, FullnodeConfig}; use crate::gossip_service::discover; -use crate::rpc::JsonRpcConfig; use crate::service::Service; use crate::thin_client::retry_get_balance; use crate::thin_client::ThinClient; @@ -36,11 +35,6 @@ impl LocalCluster { &FullnodeConfig::default(), ) } - pub fn new_unsafe(num_nodes: usize, cluster_lamports: u64, lamports_per_node: u64) -> Self { - let mut unsafe_rpc = FullnodeConfig::default(); - unsafe_rpc.rpc_config = JsonRpcConfig::Unsafe; - Self::new_with_config(num_nodes, cluster_lamports, lamports_per_node, &unsafe_rpc) - } pub fn new_with_config( num_nodes: usize, @@ -201,19 +195,22 @@ impl Drop for LocalCluster { #[cfg(test)] mod test { use super::*; + use crate::rpc::JsonRpcConfig; #[test] fn test_local_cluster_start_and_exit() { solana_logger::setup(); - let network = LocalCluster::new(1, 100, 3); - drop(network) + let cluster = LocalCluster::new(1, 100, 3); + drop(cluster) } #[test] - fn test_local_cluster_start_and_exit_unsafe() { + fn test_local_cluster_start_and_exit_with_config() { solana_logger::setup(); - let network = LocalCluster::new_unsafe(1, 100, 3); - drop(network) + let mut fullnode_exit = FullnodeConfig::default(); + fullnode_exit.rpc_config = JsonRpcConfig::TestOnlyAllowRpcFullnodeExit; + let cluster = LocalCluster::new_with_config(1, 100, 3, &fullnode_exit); + drop(cluster) } } diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 503a6fec46..35147db44f 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -23,13 +23,13 @@ use std::time::{Duration, Instant}; #[derive(Clone)] pub enum JsonRpcConfig { - Safe, - Unsafe, + DefaultConfig, + TestOnlyAllowRpcFullnodeExit, } impl Default for JsonRpcConfig { fn default() -> Self { - JsonRpcConfig::Safe + JsonRpcConfig::DefaultConfig } } @@ -111,12 +111,12 @@ impl JsonRpcRequestProcessor { pub fn fullnode_exit(&self) -> Result { match self.config { - JsonRpcConfig::Safe => { - debug!("safe config, fullnode_exit ignored"); + JsonRpcConfig::DefaultConfig => { + debug!("default config, fullnode_exit ignored"); Ok(false) } - JsonRpcConfig::Unsafe => { - warn!("JsonRPC fullnode_exit request..."); + JsonRpcConfig::TestOnlyAllowRpcFullnodeExit => { + warn!("TEST_ONLY JsonRPC fullnode_exit request..."); self.fullnode_exit.store(true, Ordering::Relaxed); Ok(true) } @@ -705,7 +705,7 @@ mod tests { } #[test] - fn test_rpc_request_processor_default_exit_is_a_noop() { + fn test_rpc_request_processor_config_default_trait_fullnode_exit_fails() { let exit = Arc::new(AtomicBool::new(false)); let request_processor = JsonRpcRequestProcessor::new( StorageState::default(), @@ -716,11 +716,11 @@ mod tests { assert_eq!(exit.load(Ordering::Relaxed), false); } #[test] - fn test_rpc_request_processor_safe_exit_is_a_noop() { + fn test_rpc_request_processor_default_config_fullnode_exit_fails() { let exit = Arc::new(AtomicBool::new(false)); let request_processor = JsonRpcRequestProcessor::new( StorageState::default(), - JsonRpcConfig::Safe, + JsonRpcConfig::DefaultConfig, exit.clone(), ); assert_eq!(request_processor.fullnode_exit(), Ok(false)); @@ -728,15 +728,14 @@ mod tests { } #[test] - fn test_rpc_request_processor_unsafe_exit() { + fn test_rpc_request_processor_allow_fullnode_exit_config() { let exit = Arc::new(AtomicBool::new(false)); let request_processor = JsonRpcRequestProcessor::new( StorageState::default(), - JsonRpcConfig::Unsafe, + JsonRpcConfig::TestOnlyAllowRpcFullnodeExit, exit.clone(), ); assert_eq!(request_processor.fullnode_exit(), Ok(true)); assert_eq!(exit.load(Ordering::Relaxed), true); } - } diff --git a/tests/local_cluster.rs b/tests/local_cluster.rs index 3611ca8183..a79294647b 100644 --- a/tests/local_cluster.rs +++ b/tests/local_cluster.rs @@ -1,7 +1,9 @@ extern crate solana; use solana::cluster_tests; +use solana::fullnode::FullnodeConfig; use solana::local_cluster::LocalCluster; +use solana::rpc::JsonRpcConfig; #[test] fn test_spend_and_verify_all_nodes_1() -> () { @@ -52,6 +54,8 @@ fn test_fullnode_exit_safe_config_should_panic_2() -> () { fn test_fullnode_exit_unsafe_config_2() -> () { solana_logger::setup(); let num_nodes = 2; - let local = LocalCluster::new_unsafe(num_nodes, 10_000, 100); + let mut fullnode_exit = FullnodeConfig::default(); + fullnode_exit.rpc_config = JsonRpcConfig::TestOnlyAllowRpcFullnodeExit; + let local = LocalCluster::new_with_config(num_nodes, 10_000, 100, &fullnode_exit); cluster_tests::fullnode_exit(&local.entry_point_info, num_nodes); }