@@ -385,6 +385,7 @@ mod tests {
385
385
use std:: ops:: Deref ;
386
386
use std:: path:: PathBuf ;
387
387
use std:: sync:: { Arc , Mutex } ;
388
+ use std:: sync:: mpsc:: SyncSender ;
388
389
use std:: time:: Duration ;
389
390
use super :: { BackgroundProcessor , FRESHNESS_TIMER } ;
390
391
@@ -427,21 +428,27 @@ mod tests {
427
428
struct Persister {
428
429
data_dir : String ,
429
430
graph_error : Option < ( std:: io:: ErrorKind , & ' static str ) > ,
431
+ graph_sender : Option < SyncSender < NetworkGraph > > ,
430
432
manager_error : Option < ( std:: io:: ErrorKind , & ' static str ) >
431
433
}
432
434
433
435
impl Persister {
434
436
fn new ( data_dir : String ) -> Self {
435
- Self { data_dir, graph_error : None , manager_error : None }
437
+ Self { data_dir, graph_error : None , manager_error : None , graph_sender : None }
436
438
}
437
439
438
440
fn with_graph_error ( self , error : std:: io:: ErrorKind , message : & ' static str ) -> Self {
439
441
Self { graph_error : Some ( ( error, message) ) , ..self }
440
442
}
441
443
444
+ fn with_graph_sender ( self , sender : SyncSender < NetworkGraph > ) -> Self {
445
+ Self { graph_sender : Some ( sender) , ..self }
446
+ }
447
+
442
448
fn with_manager_error ( self , error : std:: io:: ErrorKind , message : & ' static str ) -> Self {
443
449
Self { manager_error : Some ( ( error, message) ) , ..self }
444
450
}
451
+
445
452
}
446
453
447
454
impl < Signer : Sign , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > super :: Persister < Signer , M , T , K , F , L > for Persister where
@@ -459,6 +466,10 @@ mod tests {
459
466
}
460
467
461
468
fn persist_graph ( & self , network_graph : & NetworkGraph ) -> Result < ( ) , std:: io:: Error > {
469
+ if let Some ( sender) = & self . graph_sender {
470
+ sender. send ( network_graph. clone ( ) ) ;
471
+ } ;
472
+
462
473
match self . graph_error {
463
474
None => FilesystemPersister :: persist_network_graph ( self . data_dir . clone ( ) , network_graph) ,
464
475
Some ( ( error, message) ) => Err ( std:: io:: Error :: new ( error, message) ) ,
@@ -762,40 +773,31 @@ mod tests {
762
773
let mut nodes = create_nodes ( 2 , "test_not_pruning_network_graph_until_graph_sync_completion" . to_string ( ) ) ;
763
774
let channel_value = 100000 ;
764
775
let data_dir = nodes[ 0 ] . persister . get_data_dir ( ) ;
765
- let persister = Persister :: new ( data_dir. clone ( ) ) ;
776
+ let ( sender, receiver) = std:: sync:: mpsc:: sync_channel ( 1 ) ;
777
+ let persister = Persister :: new ( data_dir. clone ( ) ) . with_graph_sender ( sender) ;
766
778
let network_graph = nodes[ 0 ] . network_graph . clone ( ) ;
767
779
let features = ChannelFeatures :: empty ( ) ;
768
780
network_graph. update_channel_from_partial_announcement ( 42 , 53 , features, nodes[ 0 ] . node . get_our_node_id ( ) , nodes[ 1 ] . node . get_our_node_id ( ) ) ;
769
781
let original_graph_description = network_graph. to_string ( ) ;
770
782
assert ! ( original_graph_description. contains( "42: features: 0000, node_one:" ) ) ;
771
783
772
- let ( sender, receiver) = std:: sync:: mpsc:: sync_channel ( 1 ) ;
773
- let event_handler = move |event : & Event | {
774
- sender. send ( handle_funding_generation_ready ! ( event, channel_value) ) . unwrap ( ) ;
775
- } ;
784
+ let event_handler = |_: & _ | { } ;
776
785
let bg_processor = BackgroundProcessor :: start ( persister, event_handler, nodes[ 0 ] . chain_monitor . clone ( ) , nodes[ 0 ] . node . clone ( ) , nodes[ 0 ] . net_graph_msg_handler . clone ( ) , nodes[ 0 ] . peer_manager . clone ( ) , true , nodes[ 0 ] . logger . clone ( ) ) ;
777
786
778
- for i in 0 ..EVENT_DEADLINE {
779
- std:: thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
780
- let current_graph_description = network_graph. to_string ( ) ;
781
- assert_eq ! ( current_graph_description, original_graph_description)
782
- }
787
+ let reception_result = receiver
788
+ . recv_timeout ( Duration :: from_secs ( EVENT_DEADLINE ) ) ;
789
+ assert ! ( reception_result. is_err( ) ) ;
783
790
784
791
bg_processor. graph_sync_complete ( ) ;
785
792
786
- let mut seconds_slept = 0 ;
787
- loop {
788
- assert ! ( seconds_slept < 3 ) ;
789
- std:: thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
790
- seconds_slept += 1 ;
791
- let current_graph_description = network_graph. to_string ( ) ;
792
- if current_graph_description != original_graph_description {
793
- assert_eq ! ( current_graph_description. len( ) , 31 ) ;
794
- assert ! ( !current_graph_description. contains( "node_one:" ) ) ;
795
- assert ! ( !current_graph_description. contains( "node_two:" ) ) ;
796
- break
797
- }
798
- }
793
+ let graph = receiver
794
+ . recv_timeout ( Duration :: from_secs ( EVENT_DEADLINE ) )
795
+ . expect ( "SpendableOutputs not handled within deadline" ) ;
796
+ let current_graph_description = network_graph. to_string ( ) ;
797
+ assert_ne ! ( current_graph_description, original_graph_description) ;
798
+ assert_eq ! ( current_graph_description. len( ) , 31 ) ;
799
+ assert ! ( !current_graph_description. contains( "node_one:" ) ) ;
800
+ assert ! ( !current_graph_description. contains( "node_two:" ) ) ;
799
801
}
800
802
801
803
#[ test]
0 commit comments