@@ -93,21 +93,28 @@ impl ConnectionProgress {
9393 }
9494
9595 pub fn handle_pass_gossip ( & mut self , logger : & Logger , new_pass_target : IpAddr ) {
96- if self . connection_stage != ConnectionStage :: TcpConnectionEstablished {
97- panic ! (
98- "Can't update the stage from {:?} to {:?}" ,
96+ let preliminary_msg = format ! (
97+ "Pass gossip received from Node with IP Address {:?} to a Node with IP Address {:?}" ,
98+ self . current_peer_addr, new_pass_target,
99+ ) ;
100+ match self . connection_stage {
101+ ConnectionStage :: StageZero => {
102+ error ! (
103+ logger,
104+ "{preliminary_msg}. Requested to update the stage from StageZero to StageZero." ,
105+ )
106+ }
107+ ConnectionStage :: TcpConnectionEstablished => {
108+ debug ! (
109+ logger,
110+ "{preliminary_msg}. Updating the stage from TcpConnectionEstablished to StageZero." ,
111+ )
112+ }
113+ _ => panic ! (
114+ "{preliminary_msg}. Can't update the stage from {:?} to StageZero" ,
99115 self . connection_stage,
100- ConnectionStage :: StageZero
101- )
102- } ;
103-
104- debug ! (
105- logger,
106- "Pass gossip received from Node with IP Address {:?} to a Node with IP Address {:?}. \
107- Hence, updating the connection stage of the new Node to StageZero.",
108- self . current_peer_addr,
109- new_pass_target
110- ) ;
116+ ) ,
117+ }
111118
112119 self . connection_stage = ConnectionStage :: StageZero ;
113120 self . current_peer_addr = new_pass_target;
@@ -351,13 +358,13 @@ mod tests {
351358 #[ test]
352359 fn connection_progress_handles_pass_gossip_correctly_and_performs_logging_in_order ( ) {
353360 init_test_logging ( ) ;
361+ let test_name =
362+ "connection_progress_handles_pass_gossip_correctly_and_performs_logging_in_order" ;
354363 let ip_addr = make_ip ( 1 ) ;
355364 let initial_node_descriptor = make_node_descriptor ( ip_addr) ;
356365 let mut subject = ConnectionProgress :: new ( initial_node_descriptor. clone ( ) ) ;
357366 let pass_target = make_ip ( 2 ) ;
358- let logger = Logger :: new (
359- "connection_progress_handles_pass_gossip_correctly_and_performs_logging_in_order" ,
360- ) ;
367+ let logger = Logger :: new ( test_name) ;
361368 subject. update_stage ( & logger, ConnectionStage :: TcpConnectionEstablished ) ;
362369
363370 subject. handle_pass_gossip ( & logger, pass_target) ;
@@ -372,29 +379,57 @@ mod tests {
372379 ) ;
373380 TestLogHandler :: new ( ) . assert_logs_contain_in_order ( vec ! [
374381 & format!(
375- "DEBUG: connection_progress_handles_pass_gossip_correctly_and\
376- _performs_logging_in_order: The connection stage \
382+ "DEBUG: {test_name}: The connection stage \
377383 for Node with IP address {:?} has been updated from {:?} to {:?}.",
378384 ip_addr,
379385 ConnectionStage :: StageZero ,
380386 ConnectionStage :: TcpConnectionEstablished
381387 ) ,
382388 & format!(
383- "DEBUG: connection_progress_handles_pass_gossip_correctly_and_performs_logging\
384- _in_order: Pass gossip received from Node with IP Address {:?} to a Node with \
385- IP Address {:?}. Hence, updating the connection stage of the new Node to StageZero.",
389+ "DEBUG: {test_name}: Pass gossip received from Node with IP Address {:?} to a Node with \
390+ IP Address {:?}. Updating the stage from TcpConnectionEstablished to StageZero.",
386391 ip_addr, pass_target
387392 ) ,
388393 ] ) ;
389394 }
390395
391396 #[ test]
392- #[ should_panic( expected = "Can't update the stage from StageZero to StageZero" ) ]
397+ fn connection_progress_logs_error_while_handling_pass_gossip_in_case_tcp_connection_is_not_established (
398+ ) {
399+ init_test_logging ( ) ;
400+ let test_name = "connection_progress_logs_error_while_handling_pass_gossip_in_case_tcp_connection_is_not_established" ;
401+ let ip_addr = make_ip ( 1 ) ;
402+ let initial_node_descriptor = make_node_descriptor ( ip_addr) ;
403+ let mut subject = ConnectionProgress :: new ( initial_node_descriptor. clone ( ) ) ;
404+ let pass_target = make_ip ( 2 ) ;
405+
406+ subject. handle_pass_gossip ( & Logger :: new ( test_name) , pass_target) ;
407+
408+ assert_eq ! (
409+ subject,
410+ ConnectionProgress {
411+ initial_node_descriptor,
412+ current_peer_addr: pass_target,
413+ connection_stage: ConnectionStage :: StageZero
414+ }
415+ ) ;
416+ TestLogHandler :: new ( ) . exists_log_containing ( & format ! (
417+ "ERROR: {test_name}: Pass gossip received from Node with IP Address 1.1.1.1 to a Node \
418+ with IP Address 1.1.1.2. Requested to update the stage from StageZero to StageZero."
419+ ) ) ;
420+ }
421+
422+ #[ test]
423+ #[ should_panic(
424+ expected = "Pass gossip received from Node with IP Address 1.1.1.1 to a Node \
425+ with IP Address 1.1.1.2. Can't update the stage from NeighborshipEstablished to StageZero"
426+ ) ]
393427 fn connection_progress_panics_while_handling_pass_gossip_in_case_tcp_connection_is_not_established (
394428 ) {
395429 let ip_addr = make_ip ( 1 ) ;
396430 let initial_node_descriptor = make_node_descriptor ( ip_addr) ;
397431 let mut subject = ConnectionProgress :: new ( initial_node_descriptor) ;
432+ subject. connection_stage = ConnectionStage :: NeighborshipEstablished ;
398433 let pass_target = make_ip ( 2 ) ;
399434
400435 subject. handle_pass_gossip ( & Logger :: new ( "test" ) , pass_target) ;
0 commit comments