Skip to content

testing: Ensure CheckBootstrapIsPossible is safe for teardown #2582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions tests/fixture/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ func Eventually(condition func() bool, waitFor time.Duration, tick time.Duration
func AddEphemeralNode(network *tmpnet.Network, flags tmpnet.FlagsMap) *tmpnet.Node {
require := require.New(ginkgo.GinkgoT())

ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
defer cancel()
node, err := network.AddEphemeralNode(ctx, ginkgo.GinkgoWriter, flags)
node, err := network.AddEphemeralNode(DefaultContext(), ginkgo.GinkgoWriter, flags)
require.NoError(err)

ginkgo.DeferCleanup(func() {
Expand Down Expand Up @@ -188,16 +186,34 @@ func WithSuggestedGasPrice(ethClient ethclient.Client) common.Option {
return common.WithBaseFee(baseFee)
}

// Verify that a new node can bootstrap into the network.
// Verify that a new node can bootstrap into the network. This function is safe to call
// from `Teardown` by virtue of not depending on ginkgo.DeferCleanup.
func CheckBootstrapIsPossible(network *tmpnet.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, tmpnet.FlagsMap{})
WaitForHealthy(node)
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
defer cancel()

node, err := network.AddEphemeralNode(ctx, ginkgo.GinkgoWriter, tmpnet.FlagsMap{})
// AddEphemeralNode will initiate node stop if an error is encountered during start,
// so no further cleanup effort is required if an error is seen here.
require.NoError(err)

// Ensure the node is always stopped at the end of the check
defer func() {
ctx, cancel = context.WithTimeout(context.Background(), DefaultTimeout)
defer cancel()
require.NoError(node.Stop(ctx))
}()

// Check that the node becomes healthy within timeout
require.NoError(tmpnet.WaitForHealthy(ctx, node))
}

// Start a temporary network with the provided avalanchego binary.
Expand Down