@@ -681,6 +681,46 @@ mod tests {
681681 }
682682 }
683683
684+ #[ test]
685+ fn test_network_graph_persist_error ( ) {
686+ // Test that if we encounter an error during network graph persistence, an error gets returned.
687+ let nodes = create_nodes ( 2 , "test_persist_network_graph_error" . to_string ( ) ) ;
688+ open_channel ! ( nodes[ 0 ] , nodes[ 1 ] , 100000 ) ;
689+
690+ struct NetworkGraphErrorPersister {
691+ data_dir : String ,
692+ }
693+
694+ impl < Signer : Sign , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > super :: Persister < Signer , M , T , K , F , L > for NetworkGraphErrorPersister where
695+ M :: Target : ' static + chain:: Watch < Signer > ,
696+ T :: Target : ' static + BroadcasterInterface ,
697+ K :: Target : ' static + KeysInterface < Signer = Signer > ,
698+ F :: Target : ' static + FeeEstimator ,
699+ L :: Target : ' static + Logger ,
700+ {
701+ fn persist_manager ( & self , channel_manager : & ChannelManager < Signer , M , T , K , F , L > ) -> Result < ( ) , std:: io:: Error > {
702+ FilesystemPersister :: persist_manager ( self . data_dir . clone ( ) , channel_manager)
703+ }
704+
705+ fn persist_graph ( & self , _network_graph : & NetworkGraph ) -> Result < ( ) , std:: io:: Error > {
706+ Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , "test" ) )
707+ }
708+ }
709+
710+ let data_dir = nodes[ 0 ] . persister . get_data_dir ( ) ;
711+ let persister = NetworkGraphErrorPersister { data_dir } ;
712+ let event_handler = |_: & _ | { } ;
713+ 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 ( ) , nodes[ 0 ] . logger . clone ( ) ) ;
714+
715+ match bg_processor. stop ( ) {
716+ Ok ( _) => panic ! ( "Expected error persisting network graph" ) ,
717+ Err ( e) => {
718+ assert_eq ! ( e. kind( ) , std:: io:: ErrorKind :: Other ) ;
719+ assert_eq ! ( e. get_ref( ) . unwrap( ) . to_string( ) , "test" ) ;
720+ } ,
721+ }
722+ }
723+
684724 #[ test]
685725 fn test_background_event_handling ( ) {
686726 let mut nodes = create_nodes ( 2 , "test_background_event_handling" . to_string ( ) ) ;
0 commit comments