Update test_2_party_circuit_creation to run successfully
Node_a that made the request may still need to wait for
its state to be updated after the node_b's.
@@ -264,9 +264,9 @@ fn commit_2_party_circuit(circuit_id: &str, node_a: &Node, node_b: &Node) {
assert!(res.is_ok());
// Wait for the proposal to be committed for the second node
- let proposal_b;
+ let mut proposal_b;
let start = Instant::now();
- loop {
+ let proposal_a = loop {
if Instant::now().duration_since(start) > Duration::from_secs(60) {
panic!("Failed to detect proposal in time");
}
@@ -275,21 +275,28 @@ fn commit_2_party_circuit(circuit_id: &str, node_a: &Node, node_b: &Node) {
.list_proposals(None, None)
.expect("Unable to list proposals from node_b")
.data;
+
if !proposals.is_empty() {
- // Unwrap the first proposal in this list as we've already validated the list is
- // not empty
+ // Unwrap the first element in this list as we've already validated that the list
+ // is not empty
proposal_b = proposals.get(0).unwrap().clone();
- break;
- }
+ } else {
+ continue;
}
// Validate the same proposal is available to the first node
- let proposal_a = node_a
+ let proposal_a = match node_a
.admin_service_client()
.fetch_proposal(&circuit_id)
.expect("Unable to fetch proposal from node_a")
- .unwrap();
+ {
+ Some(proposal_a) => proposal_a,
+ None => continue,
+ };
+
assert_eq!(proposal_a, proposal_b);
+ break proposal_a;
+ };
// Create the `CircuitProposalVote` to be sent to a node
// Uses `true` for the `accept` argument to create a vote to accept the proposal
@@ -305,7 +312,7 @@ fn commit_2_party_circuit(circuit_id: &str, node_a: &Node, node_b: &Node) {
assert!(res.is_ok());
// Wait for the circuit to be committed for the second node
- let circuit_b;
+ let mut circuit_b;
let start = Instant::now();
loop {
if Instant::now().duration_since(start) > Duration::from_secs(60) {
@@ -316,21 +323,28 @@ fn commit_2_party_circuit(circuit_id: &str, node_a: &Node, node_b: &Node) {
.list_circuits(None)
.expect("Unable to list circuits from node_b")
.data;
+
if !circuits.is_empty() {
// Unwrap the first element in this list as we've already validated that the list
// is not empty
circuit_b = circuits.get(0).unwrap().clone();
- break;
- }
+ } else {
+ continue;
}
// Validate the circuit is available to the first node
- let circuit_a = node_a
+ let circuit_a = match node_a
.admin_service_client()
.fetch_circuit(&circuit_id)
- .expect("Unable to fetch circuit from node_a")
- .unwrap();
+ .expect("Unable to list circuits from node_b")
+ {
+ Some(circuit) => circuit,
+ None => continue,
+ };
+
assert_eq!(circuit_a, circuit_b);
+ break;
+ }
}
/// Commit a 3-party circuit on a network that is already running
@@ -506,7 +520,6 @@ fn commit_3_party_circuit(circuit_id: &str, node_a: &Node, node_b: &Node, node_c
/// 5. Wait until the circuit is available on the first node, using `list_circuits`
/// 6. Verify the same circuit is available to each node
#[test]
-#[ignore]
pub fn test_2_party_circuit_creation() {
// Start a 2-node network
let mut network = Network::new()
