review comments; rename Unsafe to TestOnlyAllowRpcFullnodeExit

This commit is contained in:
Anatoly Yakovenko 2019-03-04 09:59:36 -08:00 committed by Grimes
parent 5aaaa7f45c
commit 3a4018cd03
3 changed files with 25 additions and 25 deletions

View File

@ -3,7 +3,6 @@ use crate::client::mk_client;
use crate::cluster_info::{Node, NodeInfo}; use crate::cluster_info::{Node, NodeInfo};
use crate::fullnode::{Fullnode, FullnodeConfig}; use crate::fullnode::{Fullnode, FullnodeConfig};
use crate::gossip_service::discover; use crate::gossip_service::discover;
use crate::rpc::JsonRpcConfig;
use crate::service::Service; use crate::service::Service;
use crate::thin_client::retry_get_balance; use crate::thin_client::retry_get_balance;
use crate::thin_client::ThinClient; use crate::thin_client::ThinClient;
@ -36,11 +35,6 @@ impl LocalCluster {
&FullnodeConfig::default(), &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( pub fn new_with_config(
num_nodes: usize, num_nodes: usize,
@ -201,19 +195,22 @@ impl Drop for LocalCluster {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use crate::rpc::JsonRpcConfig;
#[test] #[test]
fn test_local_cluster_start_and_exit() { fn test_local_cluster_start_and_exit() {
solana_logger::setup(); solana_logger::setup();
let network = LocalCluster::new(1, 100, 3); let cluster = LocalCluster::new(1, 100, 3);
drop(network) drop(cluster)
} }
#[test] #[test]
fn test_local_cluster_start_and_exit_unsafe() { fn test_local_cluster_start_and_exit_with_config() {
solana_logger::setup(); solana_logger::setup();
let network = LocalCluster::new_unsafe(1, 100, 3); let mut fullnode_exit = FullnodeConfig::default();
drop(network) fullnode_exit.rpc_config = JsonRpcConfig::TestOnlyAllowRpcFullnodeExit;
let cluster = LocalCluster::new_with_config(1, 100, 3, &fullnode_exit);
drop(cluster)
} }
} }

View File

@ -23,13 +23,13 @@ use std::time::{Duration, Instant};
#[derive(Clone)] #[derive(Clone)]
pub enum JsonRpcConfig { pub enum JsonRpcConfig {
Safe, DefaultConfig,
Unsafe, TestOnlyAllowRpcFullnodeExit,
} }
impl Default for JsonRpcConfig { impl Default for JsonRpcConfig {
fn default() -> Self { fn default() -> Self {
JsonRpcConfig::Safe JsonRpcConfig::DefaultConfig
} }
} }
@ -111,12 +111,12 @@ impl JsonRpcRequestProcessor {
pub fn fullnode_exit(&self) -> Result<bool> { pub fn fullnode_exit(&self) -> Result<bool> {
match self.config { match self.config {
JsonRpcConfig::Safe => { JsonRpcConfig::DefaultConfig => {
debug!("safe config, fullnode_exit ignored"); debug!("default config, fullnode_exit ignored");
Ok(false) Ok(false)
} }
JsonRpcConfig::Unsafe => { JsonRpcConfig::TestOnlyAllowRpcFullnodeExit => {
warn!("JsonRPC fullnode_exit request..."); warn!("TEST_ONLY JsonRPC fullnode_exit request...");
self.fullnode_exit.store(true, Ordering::Relaxed); self.fullnode_exit.store(true, Ordering::Relaxed);
Ok(true) Ok(true)
} }
@ -705,7 +705,7 @@ mod tests {
} }
#[test] #[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 exit = Arc::new(AtomicBool::new(false));
let request_processor = JsonRpcRequestProcessor::new( let request_processor = JsonRpcRequestProcessor::new(
StorageState::default(), StorageState::default(),
@ -716,11 +716,11 @@ mod tests {
assert_eq!(exit.load(Ordering::Relaxed), false); assert_eq!(exit.load(Ordering::Relaxed), false);
} }
#[test] #[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 exit = Arc::new(AtomicBool::new(false));
let request_processor = JsonRpcRequestProcessor::new( let request_processor = JsonRpcRequestProcessor::new(
StorageState::default(), StorageState::default(),
JsonRpcConfig::Safe, JsonRpcConfig::DefaultConfig,
exit.clone(), exit.clone(),
); );
assert_eq!(request_processor.fullnode_exit(), Ok(false)); assert_eq!(request_processor.fullnode_exit(), Ok(false));
@ -728,15 +728,14 @@ mod tests {
} }
#[test] #[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 exit = Arc::new(AtomicBool::new(false));
let request_processor = JsonRpcRequestProcessor::new( let request_processor = JsonRpcRequestProcessor::new(
StorageState::default(), StorageState::default(),
JsonRpcConfig::Unsafe, JsonRpcConfig::TestOnlyAllowRpcFullnodeExit,
exit.clone(), exit.clone(),
); );
assert_eq!(request_processor.fullnode_exit(), Ok(true)); assert_eq!(request_processor.fullnode_exit(), Ok(true));
assert_eq!(exit.load(Ordering::Relaxed), true); assert_eq!(exit.load(Ordering::Relaxed), true);
} }
} }

View File

@ -1,7 +1,9 @@
extern crate solana; extern crate solana;
use solana::cluster_tests; use solana::cluster_tests;
use solana::fullnode::FullnodeConfig;
use solana::local_cluster::LocalCluster; use solana::local_cluster::LocalCluster;
use solana::rpc::JsonRpcConfig;
#[test] #[test]
fn test_spend_and_verify_all_nodes_1() -> () { 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() -> () { fn test_fullnode_exit_unsafe_config_2() -> () {
solana_logger::setup(); solana_logger::setup();
let num_nodes = 2; 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); cluster_tests::fullnode_exit(&local.entry_point_info, num_nodes);
} }