Skip to content

Commit

Permalink
fixup: Ensure node stop is attempted on start failure
Browse files Browse the repository at this point in the history
  • Loading branch information
marun committed Nov 12, 2023
1 parent 0693d50 commit c127b49
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 7 additions & 6 deletions tests/fixture/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,18 @@ func CheckBootstrapIsPossible(network testnet.Network) {
}
ginkgo.By("checking if bootstrap is possible with the current network state")

// Call network.AddEphemeralNode instead of AddEphemeralNode for compatibility
// Call network.AddEphemeralNode instead of AddEphemeralNode to support
// checking for bootstrap implicitly on teardown via a function registered
// with ginkgo.DeferCleanup. It's not possible to call DeferCleanup from
// within a function called by DeferCleanup.
node, err := network.AddEphemeralNode(ginkgo.GinkgoWriter, testnet.FlagsMap{})
require.NoError(err)

defer func() {
if node != nil {
tests.Outf("Shutting down ephemeral node %s\n", node.GetID())
require.NoError(node.Stop())
}
tests.Outf("Shutting down ephemeral node %s\n", node.GetID())
require.NoError(node.Stop())
}()
require.NoError(err)

WaitForHealthy(node)
}

Expand Down
14 changes: 13 additions & 1 deletion tests/fixture/testnet/local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,19 @@ func (ln *LocalNetwork) AddLocalNode(w io.Writer, node *LocalNode, isEphemeral b
if err := node.WriteConfig(); err != nil {
return nil, err
}
return node, node.Start(w, ln.ExecPath)

err = node.Start(w, ln.ExecPath)
if err != nil {
// Attempt to stop an unhealthy node to provide some assurance to the caller
// that an error condition will not result in a lingering process.
stopErr := node.Stop()
if stopErr != nil {
err = errors.Join(err, stopErr)
}
return nil, err
}

return node, nil
}

func (ln *LocalNetwork) GetBootstrapIPsAndIDs() ([]string, []string, error) {
Expand Down

0 comments on commit c127b49

Please sign in to comment.