diff --git a/tests/e2e/ignore.go b/tests/e2e/ignore.go new file mode 100644 index 000000000000..50332a1ac80e --- /dev/null +++ b/tests/e2e/ignore.go @@ -0,0 +1,13 @@ +// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package e2e + +// This file is required by ginkgo to accurately report compilation errors in test packages. Without +// it, the following error will mask the actual errors: +// +// ``` +// Failed to compile e2e: +// +// github.com/ava-labs/avalanchego/tests/e2e: no non-test Go files in /path/to/avalanchego/tests/e2e +// ``` diff --git a/tests/fixture/e2e/helpers.go b/tests/fixture/e2e/helpers.go index cc1e22ae3aa9..15da611324e0 100644 --- a/tests/fixture/e2e/helpers.go +++ b/tests/fixture/e2e/helpers.go @@ -146,7 +146,10 @@ func AddEphemeralNode(network testnet.Network, flags testnet.FlagsMap) testnet.N // Wait for the given node to report healthy. func WaitForHealthy(node testnet.Node) { - require.NoError(ginkgo.GinkgoT(), testnet.WaitForHealthy(DefaultContext(), node)) + // Need to use explicit context (vs DefaultContext()) to support use with DeferCleanup + ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout) + defer cancel() + require.NoError(ginkgo.GinkgoT(), testnet.WaitForHealthy(ctx, node)) } // Sends an eth transaction, waits for the transaction receipt to be issued @@ -195,12 +198,26 @@ func WithSuggestedGasPrice(ethClient ethclient.Client) common.Option { // Verify that a new node can bootstrap into the network. func CheckBootstrapIsPossible(network testnet.Network) { + require := require.New(ginkgo.GinkgoT()) + if len(os.Getenv(SkipBootstrapChecksEnvName)) > 0 { tests.Outf("{{yellow}}Skipping bootstrap check due to the %s env var being set", SkipBootstrapChecksEnvName) return } ginkgo.By("checking if bootstrap is possible with the current network state") - node := AddEphemeralNode(network, testnet.FlagsMap{}) + + // 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() { + tests.Outf("Shutting down ephemeral node %s\n", node.GetID()) + require.NoError(node.Stop()) + }() + WaitForHealthy(node) } diff --git a/tests/fixture/testnet/local/network.go b/tests/fixture/testnet/local/network.go index 4f83a7fb0869..836a1489c2dd 100644 --- a/tests/fixture/testnet/local/network.go +++ b/tests/fixture/testnet/local/network.go @@ -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) {