Skip to content

Commit

Permalink
Disable Rpc module for other tests to prevent port conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Aug 15, 2018
1 parent dee3ad1 commit 7d4b21b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/bin/fullnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ fn main() -> () {
let testnet_addr: SocketAddr = testnet_address_string.parse().unwrap();
drone_addr.set_ip(testnet_addr.ip());

Fullnode::new(node, false, ledger_path, keypair, Some(testnet_addr))
Fullnode::new(node, false, ledger_path, keypair, Some(testnet_addr), true)
} else {
node.data.leader_id = node.data.id;

Fullnode::new(node, true, ledger_path, keypair, None)
Fullnode::new(node, true, ledger_path, keypair, None, true)
};

let mut client = mk_client(&repl_clone);
Expand Down
1 change: 1 addition & 0 deletions src/drone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ mod tests {
exit.clone(),
&ledger_path,
false,
false,
);
//TODO: this seems unstable
sleep(Duration::from_millis(900));
Expand Down
34 changes: 24 additions & 10 deletions src/fullnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl Fullnode {
keypair: Keypair,
network_entry_for_validator: Option<SocketAddr>,
sigverify_disabled: bool,
json_rpc_enabled: bool,
) -> Self {
info!("creating bank...");
let bank = Bank::new_default(leader);
Expand Down Expand Up @@ -93,6 +94,7 @@ impl Fullnode {
exit.clone(),
Some(ledger_path),
sigverify_disabled,
json_rpc_enabled,
);
info!(
"validator ready... local request address: {} (advertising {}) connected to: {}",
Expand All @@ -111,6 +113,7 @@ impl Fullnode {
exit.clone(),
ledger_path,
sigverify_disabled,
json_rpc_enabled,
);
info!(
"leader ready... local request address: {} (advertising {})",
Expand All @@ -126,6 +129,7 @@ impl Fullnode {
ledger: &str,
keypair: Keypair,
network_entry_for_validator: Option<SocketAddr>,
json_rpc_enabled: bool,
) -> Self {
Self::new_internal(
node,
Expand All @@ -134,6 +138,7 @@ impl Fullnode {
keypair,
network_entry_for_validator,
false,
json_rpc_enabled,
)
}

Expand All @@ -143,6 +148,7 @@ impl Fullnode {
ledger_path: &str,
keypair: Keypair,
network_entry_for_validator: Option<SocketAddr>,
json_rpc_enabled: bool,
) -> Self {
Self::new_internal(
node,
Expand All @@ -151,6 +157,7 @@ impl Fullnode {
keypair,
network_entry_for_validator,
true,
json_rpc_enabled,
)
}

Expand Down Expand Up @@ -187,6 +194,7 @@ impl Fullnode {
exit: Arc<AtomicBool>,
ledger_path: &str,
sigverify_disabled: bool,
json_rpc_enabled: bool,
) -> Self {
let tick_duration = None;
// TODO: To light up PoH, uncomment the following line:
Expand All @@ -202,10 +210,12 @@ impl Fullnode {
);
thread_hdls.extend(rpu.thread_hdls());

let mut rpc_addr = node.data.contact_info.ncp;
rpc_addr.set_port(RPC_PORT);
let rpc_service = JsonRpcService::new(bank.clone(), rpc_addr);
thread_hdls.extend(rpc_service.thread_hdls());
if json_rpc_enabled {
let mut rpc_addr = node.data.contact_info.ncp;
rpc_addr.set_port(RPC_PORT);
let rpc_service = JsonRpcService::new(bank.clone(), rpc_addr);
thread_hdls.extend(rpc_service.thread_hdls());
}

let blob_recycler = BlobRecycler::default();
let window =
Expand Down Expand Up @@ -287,6 +297,7 @@ impl Fullnode {
exit: Arc<AtomicBool>,
ledger_path: Option<&str>,
_sigverify_disabled: bool,
json_rpc_enabled: bool,
) -> Self {
let bank = Arc::new(bank);
let mut thread_hdls = vec![];
Expand All @@ -298,10 +309,12 @@ impl Fullnode {
);
thread_hdls.extend(rpu.thread_hdls());

let mut rpc_addr = node.data.contact_info.ncp;
rpc_addr.set_port(RPC_PORT);
let rpc_service = JsonRpcService::new(bank.clone(), rpc_addr);
thread_hdls.extend(rpc_service.thread_hdls());
if json_rpc_enabled {
let mut rpc_addr = node.data.contact_info.ncp;
rpc_addr.set_port(RPC_PORT);
let rpc_service = JsonRpcService::new(bank.clone(), rpc_addr);
thread_hdls.extend(rpc_service.thread_hdls());
}

let blob_recycler = BlobRecycler::default();
let window =
Expand Down Expand Up @@ -380,7 +393,8 @@ mod tests {
let bank = Bank::new(&alice);
let exit = Arc::new(AtomicBool::new(false));
let entry = tn.data.clone();
let v = Fullnode::new_validator(keypair, bank, 0, &[], tn, &entry, exit, None, false);
let v =
Fullnode::new_validator(keypair, bank, 0, &[], tn, &entry, exit, None, false, false);
v.exit();
v.join().unwrap();
}
Expand All @@ -394,7 +408,7 @@ mod tests {
let bank = Bank::new(&alice);
let exit = Arc::new(AtomicBool::new(false));
let entry = tn.data.clone();
Fullnode::new_validator(keypair, bank, 0, &[], tn, &entry, exit, None, false)
Fullnode::new_validator(keypair, bank, 0, &[], tn, &entry, exit, None, false, false)
})
.collect();
//each validator can exit in parallel to speed many sequential calls to `join`
Expand Down
3 changes: 3 additions & 0 deletions src/thin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ mod tests {
exit.clone(),
&ledger_path,
false,
false,
);
sleep(Duration::from_millis(900));

Expand Down Expand Up @@ -412,6 +413,7 @@ mod tests {
exit.clone(),
&ledger_path,
false,
false,
);
//TODO: remove this sleep, or add a retry so CI is stable
sleep(Duration::from_millis(300));
Expand Down Expand Up @@ -471,6 +473,7 @@ mod tests {
exit.clone(),
&ledger_path,
false,
false,
);
sleep(Duration::from_millis(300));

Expand Down
55 changes: 48 additions & 7 deletions tests/multinode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,14 @@ fn test_multi_node_ledger_window() -> result::Result<()> {
writer.write_entries(entries).unwrap();
}

let leader = Fullnode::new(leader, true, &leader_ledger_path, leader_keypair, None);
let leader = Fullnode::new(
leader,
true,
&leader_ledger_path,
leader_keypair,
None,
false,
);

// Send leader some tokens to vote
let leader_balance =
Expand All @@ -164,6 +171,7 @@ fn test_multi_node_ledger_window() -> result::Result<()> {
&zero_ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);

// contains the leader and new node
Expand Down Expand Up @@ -219,7 +227,14 @@ fn test_multi_node_validator_catchup_from_zero() -> result::Result<()> {
);
ledger_paths.push(zero_ledger_path.clone());

let server = Fullnode::new(leader, true, &leader_ledger_path, leader_keypair, None);
let server = Fullnode::new(
leader,
true,
&leader_ledger_path,
leader_keypair,
None,
false,
);

// Send leader some tokens to vote
let leader_balance =
Expand All @@ -242,6 +257,7 @@ fn test_multi_node_validator_catchup_from_zero() -> result::Result<()> {
&ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);
nodes.push(val);
}
Expand Down Expand Up @@ -277,6 +293,7 @@ fn test_multi_node_validator_catchup_from_zero() -> result::Result<()> {
&zero_ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);
nodes.push(val);
//contains the leader and new node
Expand Down Expand Up @@ -336,7 +353,14 @@ fn test_multi_node_basic() {

let (alice, leader_ledger_path) = genesis("multi_node_basic", 10_000);
ledger_paths.push(leader_ledger_path.clone());
let server = Fullnode::new(leader, true, &leader_ledger_path, leader_keypair, None);
let server = Fullnode::new(
leader,
true,
&leader_ledger_path,
leader_keypair,
None,
false,
);

// Send leader some tokens to vote
let leader_balance =
Expand All @@ -355,6 +379,7 @@ fn test_multi_node_basic() {
&ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);
nodes.push(val);
}
Expand Down Expand Up @@ -397,7 +422,14 @@ fn test_boot_validator_from_file() -> result::Result<()> {
ledger_paths.push(leader_ledger_path.clone());

let leader_data = leader.data.clone();
let leader_fullnode = Fullnode::new(leader, true, &leader_ledger_path, leader_keypair, None);
let leader_fullnode = Fullnode::new(
leader,
true,
&leader_ledger_path,
leader_keypair,
None,
false,
);
let leader_balance =
send_tx_and_retry_get_balance(&leader_data, &alice, &bob_pubkey, Some(500)).unwrap();
assert_eq!(leader_balance, 500);
Expand All @@ -416,6 +448,7 @@ fn test_boot_validator_from_file() -> result::Result<()> {
&ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);
let mut client = mk_client(&validator_data);
let getbal = retry_get_balance(&mut client, &bob_pubkey, Some(leader_balance));
Expand All @@ -434,7 +467,7 @@ fn create_leader(ledger_path: &str) -> (NodeInfo, Fullnode) {
let leader_keypair = Keypair::new();
let leader = TestNode::new_localhost_with_pubkey(leader_keypair.pubkey());
let leader_data = leader.data.clone();
let leader_fullnode = Fullnode::new(leader, true, &ledger_path, leader_keypair, None);
let leader_fullnode = Fullnode::new(leader, true, &ledger_path, leader_keypair, None, false);
(leader_data, leader_fullnode)
}

Expand Down Expand Up @@ -485,6 +518,7 @@ fn test_leader_restart_validator_start_from_old_ledger() -> result::Result<()> {
&stale_ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);

// trigger broadcast, validator should catch up from leader, whose window contains
Expand Down Expand Up @@ -547,8 +581,14 @@ fn test_multi_node_dynamic_network() {
let alice_arc = Arc::new(RwLock::new(alice));
let leader_data = leader.data.clone();

let server =
Fullnode::new_without_sigverify(leader, true, &leader_ledger_path, leader_keypair, None);
let server = Fullnode::new_without_sigverify(
leader,
true,
&leader_ledger_path,
leader_keypair,
None,
false,
);

// Send leader some tokens to vote
let leader_balance = send_tx_and_retry_get_balance(
Expand Down Expand Up @@ -622,6 +662,7 @@ fn test_multi_node_dynamic_network() {
&ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);
(rd, val)
})
Expand Down

0 comments on commit 7d4b21b

Please sign in to comment.