mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
itest: clean up harness helper methods
Refactor harness helper methods in the integration test package to reduce cleanup noise and keep setup code consistent across test helpers.
This commit is contained in:
parent
acf4e46561
commit
1ce3fce3bd
3 changed files with 47 additions and 11 deletions
|
|
@ -1428,7 +1428,20 @@ func (hn *HarnessNode) Stop() error {
|
|||
select {
|
||||
case <-hn.processExit:
|
||||
case <-time.After(lntest.DefaultTimeout * 2):
|
||||
return fmt.Errorf("process did not exit")
|
||||
if hn.cmd != nil && hn.cmd.Process != nil {
|
||||
if err := hn.cmd.Process.Kill(); err != nil &&
|
||||
!errors.Is(err, os.ErrProcessDone) {
|
||||
|
||||
return fmt.Errorf("process did not exit and "+
|
||||
"could not be killed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
select {
|
||||
case <-hn.processExit:
|
||||
case <-time.After(lntest.DefaultTimeout):
|
||||
return fmt.Errorf("process did not exit")
|
||||
}
|
||||
}
|
||||
|
||||
close(hn.quit)
|
||||
|
|
|
|||
|
|
@ -73,6 +73,10 @@ type NetworkHarness struct {
|
|||
// to main process.
|
||||
lndErrorChan chan error
|
||||
|
||||
// lndErrorChanClosed is set to true once lndErrorChan has been closed,
|
||||
// guarded by mtx to prevent double-close.
|
||||
lndErrorChanClosed bool
|
||||
|
||||
mtx sync.Mutex
|
||||
}
|
||||
|
||||
|
|
@ -131,6 +135,12 @@ func (n *NetworkHarness) SetUp(t *testing.T, testCase string, lndArgs []string,
|
|||
grpclog.SetLoggerV2(fakeLogger)
|
||||
n.currentTestCase = testCase
|
||||
|
||||
t.Cleanup(func() {
|
||||
tearDownErr := n.TearDown()
|
||||
n.Stop()
|
||||
require.NoError(t, tearDownErr)
|
||||
})
|
||||
|
||||
// Start our mock Loop/Pool server first.
|
||||
mockServerAddr := fmt.Sprintf(
|
||||
node.ListenerFormat, port.NextAvailablePort(),
|
||||
|
|
@ -257,11 +267,6 @@ out:
|
|||
}
|
||||
}
|
||||
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, n.TearDown())
|
||||
n.Stop()
|
||||
})
|
||||
|
||||
n.EnsureConnected(t, n.Alice, n.Bob)
|
||||
|
||||
logLine := "STARTING ============ %v ============\n"
|
||||
|
|
@ -274,20 +279,36 @@ out:
|
|||
|
||||
// TearDown tears down all active nodes within the test lightning network.
|
||||
func (n *NetworkHarness) TearDown() error {
|
||||
var tearDownErr error
|
||||
|
||||
for _, node := range n.activeNodes {
|
||||
if err := n.ShutdownNode(node); err != nil {
|
||||
return err
|
||||
if tearDownErr == nil {
|
||||
tearDownErr = err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return tearDownErr
|
||||
}
|
||||
|
||||
// Stop stops the test harness.
|
||||
func (n *NetworkHarness) Stop() {
|
||||
close(n.lndErrorChan)
|
||||
if n.server != nil {
|
||||
n.server.Stop()
|
||||
}
|
||||
|
||||
n.autopilotServer.Stop()
|
||||
if n.autopilotServer != nil {
|
||||
n.autopilotServer.Stop()
|
||||
}
|
||||
|
||||
n.mtx.Lock()
|
||||
defer n.mtx.Unlock()
|
||||
|
||||
if !n.lndErrorChanClosed {
|
||||
close(n.lndErrorChan)
|
||||
n.lndErrorChanClosed = true
|
||||
}
|
||||
}
|
||||
|
||||
func (n *NetworkHarness) litArgs() []string {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,9 @@ func NewServerHarness(serverHost string) *ServerHarness {
|
|||
|
||||
// Stop stops the mock Loop/Pool server.
|
||||
func (s *ServerHarness) Stop() {
|
||||
s.mockServer.Stop()
|
||||
if s.mockServer != nil {
|
||||
s.mockServer.Stop()
|
||||
}
|
||||
s.wg.Wait()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue