@@ -636,12 +636,11 @@ func (hn *HarnessNode) cleanup() error {
636
636
// waitForProcessExit Launch a new goroutine which that bubbles up any
637
637
// potential fatal process errors to the goroutine running the tests.
638
638
func (hn * HarnessNode ) WaitForProcessExit () error {
639
- var err error
639
+ var errReturned error
640
640
641
641
errChan := make (chan error , 1 )
642
642
go func () {
643
- err = hn .cmd .Wait ()
644
- errChan <- err
643
+ errChan <- hn .cmd .Wait ()
645
644
}()
646
645
647
646
select {
@@ -656,24 +655,36 @@ func (hn *HarnessNode) WaitForProcessExit() error {
656
655
return nil
657
656
}
658
657
658
+ // The process may have already been killed in the test, in
659
+ // that case we will skip the error and continue processing
660
+ // the logs.
661
+ if strings .Contains (err .Error (), "signal: killed" ) {
662
+ break
663
+ }
664
+
659
665
// Otherwise, we print the error, break the select and save
660
666
// logs.
661
667
hn .printErrf ("wait process exit got err: %v" , err )
662
-
663
- break
668
+ errReturned = err
664
669
665
670
case <- time .After (wait .DefaultTimeout ):
666
671
hn .printErrf ("timeout waiting for process to exit" )
667
672
}
668
673
669
674
// Make sure log file is closed and renamed if necessary.
670
- finalizeLogfile (hn )
675
+ filename := finalizeLogfile (hn )
671
676
672
- // Rename the etcd.log file if the node was running on embedded
673
- // etcd.
677
+ // Assert the node has shut down from the log file.
678
+ err1 := assertNodeShutdown (filename )
679
+ if err1 != nil {
680
+ return fmt .Errorf ("[%s]: assert shutdown failed in log[%s]: %w" ,
681
+ hn .Name (), filename , err1 )
682
+ }
683
+
684
+ // Rename the etcd.log file if the node was running on embedded etcd.
674
685
finalizeEtcdLog (hn )
675
686
676
- return err
687
+ return errReturned
677
688
}
678
689
679
690
// Stop attempts to stop the active lnd process.
@@ -700,30 +711,29 @@ func (hn *HarnessNode) Stop() error {
700
711
701
712
err := wait .NoError (func () error {
702
713
_ , err := hn .RPC .LN .StopDaemon (ctxt , & req )
703
-
704
- switch {
705
- case err == nil :
714
+ if err == nil {
706
715
return nil
716
+ }
707
717
708
- // Try again if a recovery/rescan is in progress.
709
- case strings .Contains (
710
- err .Error (), "recovery in progress" ,
711
- ):
712
- return err
713
-
714
- default :
718
+ // If the connection is already closed, we can exit
719
+ // early as the node has already been shut down in the
720
+ // test, e.g., in etcd leader health check test.
721
+ if strings .Contains (err .Error (), "connection refused" ) {
715
722
return nil
716
723
}
724
+
725
+ return err
717
726
}, wait .DefaultTimeout )
718
727
if err != nil {
719
- return err
728
+ return fmt . Errorf ( "shutdown timeout: %w" , err )
720
729
}
721
730
722
731
// Wait for goroutines to be finished.
723
732
done := make (chan struct {})
724
733
go func () {
725
734
hn .Watcher .wg .Wait ()
726
735
close (done )
736
+ hn .Watcher = nil
727
737
}()
728
738
729
739
// If the goroutines fail to finish before timeout, we'll print
@@ -966,31 +976,23 @@ func getFinalizedLogFilePrefix(hn *HarnessNode) string {
966
976
967
977
// finalizeLogfile makes sure the log file cleanup function is initialized,
968
978
// even if no log file is created.
969
- func finalizeLogfile (hn * HarnessNode ) {
979
+ func finalizeLogfile (hn * HarnessNode ) string {
970
980
// Exit early if there's no log file.
971
981
if hn .logFile == nil {
972
- return
982
+ return ""
973
983
}
974
984
975
985
hn .logFile .Close ()
976
986
977
987
// If logoutput flag is not set, return early.
978
988
if ! * logOutput {
979
- return
989
+ return ""
980
990
}
981
991
982
- newFileName := fmt .Sprintf ("%v.log" ,
983
- getFinalizedLogFilePrefix (hn ),
984
- )
992
+ newFileName := fmt .Sprintf ("%v.log" , getFinalizedLogFilePrefix (hn ))
985
993
renameFile (hn .filename , newFileName )
986
994
987
- // Assert the node has shut down from the log file.
988
- err := assertNodeShutdown (newFileName )
989
- if err != nil {
990
- err := fmt .Errorf ("[%s]: assert shutdown failed in log[%s]: %w" ,
991
- hn .Name (), newFileName , err )
992
- panic (err )
993
- }
995
+ return newFileName
994
996
}
995
997
996
998
// assertNodeShutdown asserts that the node has shut down properly by checking
0 commit comments