Make room for more fields in JsonRpcConfig

This commit is contained in:
Michael Vines 2019-03-05 21:12:30 -08:00
parent b850f3c1dd
commit b03fd782de
4 changed files with 27 additions and 43 deletions

View File

@ -211,7 +211,6 @@ impl Drop for LocalCluster {
#[cfg(test)]
mod test {
use super::*;
use crate::rpc::JsonRpcConfig;
#[test]
fn test_local_cluster_start_and_exit() {
@ -224,7 +223,7 @@ mod test {
fn test_local_cluster_start_and_exit_with_config() {
solana_logger::setup();
let mut fullnode_exit = FullnodeConfig::default();
fullnode_exit.rpc_config = JsonRpcConfig::TestOnlyAllowRpcFullnodeExit;
fullnode_exit.rpc_config.enable_fullnode_exit = true;
let cluster = LocalCluster::new_with_config(1, 100, 3, &fullnode_exit);
drop(cluster)
}

View File

@ -22,14 +22,15 @@ use std::thread::sleep;
use std::time::{Duration, Instant};
#[derive(Clone)]
pub enum JsonRpcConfig {
DefaultConfig,
TestOnlyAllowRpcFullnodeExit,
pub struct JsonRpcConfig {
pub enable_fullnode_exit: bool, // Enable the 'fullnodeExit' command
}
impl Default for JsonRpcConfig {
fn default() -> Self {
JsonRpcConfig::DefaultConfig
Self {
enable_fullnode_exit: false,
}
}
}
@ -110,16 +111,13 @@ impl JsonRpcRequestProcessor {
}
pub fn fullnode_exit(&self) -> Result<bool> {
match self.config {
JsonRpcConfig::DefaultConfig => {
debug!("default config, fullnode_exit ignored");
Ok(false)
}
JsonRpcConfig::TestOnlyAllowRpcFullnodeExit => {
warn!("TEST_ONLY JsonRPC fullnode_exit request...");
self.fullnode_exit.store(true, Ordering::Relaxed);
Ok(true)
}
if self.config.enable_fullnode_exit {
warn!("fullnode_exit request...");
self.fullnode_exit.store(true, Ordering::Relaxed);
Ok(true)
} else {
debug!("fullnode_exit ignored");
Ok(false)
}
}
}
@ -714,26 +712,14 @@ mod tests {
assert_eq!(request_processor.fullnode_exit(), Ok(false));
assert_eq!(exit.load(Ordering::Relaxed), false);
}
#[test]
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::DefaultConfig,
&exit,
);
assert_eq!(request_processor.fullnode_exit(), Ok(false));
assert_eq!(exit.load(Ordering::Relaxed), false);
}
#[test]
fn test_rpc_request_processor_allow_fullnode_exit_config() {
let exit = Arc::new(AtomicBool::new(false));
let request_processor = JsonRpcRequestProcessor::new(
StorageState::default(),
JsonRpcConfig::TestOnlyAllowRpcFullnodeExit,
&exit,
);
let mut config = JsonRpcConfig::default();
config.enable_fullnode_exit = true;
let request_processor =
JsonRpcRequestProcessor::new(StorageState::default(), config, &exit);
assert_eq!(request_processor.fullnode_exit(), Ok(true));
assert_eq!(exit.load(Ordering::Relaxed), true);
}

View File

@ -217,7 +217,7 @@ fn main() {
let use_only_bootstrap_leader = matches.is_present("no_leader_rotation");
if matches.is_present("enable_rpc_exit") {
fullnode_config.rpc_config = solana::rpc::JsonRpcConfig::TestOnlyAllowRpcFullnodeExit;
fullnode_config.rpc_config.enable_fullnode_exit = true;
}
let gossip_addr = {

View File

@ -3,7 +3,6 @@ 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() {
@ -54,18 +53,18 @@ fn test_fullnode_exit_default_config_should_panic() {
fn test_fullnode_exit_2() {
solana_logger::setup();
let num_nodes = 2;
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);
let mut fullnode_config = FullnodeConfig::default();
fullnode_config.rpc_config.enable_fullnode_exit = true;
let local = LocalCluster::new_with_config(num_nodes, 10_000, 100, &fullnode_config);
cluster_tests::fullnode_exit(&local.entry_point_info, num_nodes);
}
#[test]
fn test_leader_failure_2() {
let num_nodes = 2;
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);
let mut fullnode_config = FullnodeConfig::default();
fullnode_config.rpc_config.enable_fullnode_exit = true;
let local = LocalCluster::new_with_config(num_nodes, 10_000, 100, &fullnode_config);
cluster_tests::kill_entry_and_spend_and_verify_rest(
&local.entry_point_info,
&local.funding_keypair,
@ -76,9 +75,9 @@ fn test_leader_failure_2() {
#[test]
fn test_leader_failure_3() {
let num_nodes = 3;
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);
let mut fullnode_config = FullnodeConfig::default();
fullnode_config.rpc_config.enable_fullnode_exit = true;
let local = LocalCluster::new_with_config(num_nodes, 10_000, 100, &fullnode_config);
cluster_tests::kill_entry_and_spend_and_verify_rest(
&local.entry_point_info,
&local.funding_keypair,