From 2c84afeb6d8eb5fcf57c399a94dfd755305feb9d Mon Sep 17 00:00:00 2001 From: marun Date: Fri, 18 Oct 2024 11:51:55 -0700 Subject: [PATCH] [tmpnet] Add --start-network to support hypersdk MODE=run (#3465) --- tests/fixture/e2e/env.go | 6 ++++++ tests/fixture/e2e/flags.go | 17 ++++++++++++++--- tests/fixture/e2e/helpers.go | 6 ++++++ tests/upgrade/upgrade_test.go | 10 +++++++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/tests/fixture/e2e/env.go b/tests/fixture/e2e/env.go index 34748a9877d9..1dac79b8d29a 100644 --- a/tests/fixture/e2e/env.go +++ b/tests/fixture/e2e/env.go @@ -135,6 +135,7 @@ func NewTestEnvironment(tc tests.TestContext, flagVars *FlagVars, desiredNetwork flagVars.AvalancheGoExecPath(), flagVars.PluginDir(), flagVars.NetworkShutdownDelay(), + flagVars.StartNetwork(), flagVars.ReuseNetwork(), ) @@ -158,6 +159,10 @@ func NewTestEnvironment(tc tests.TestContext, flagVars *FlagVars, desiredNetwork }, DefaultTimeout, DefaultPollingInterval, "failed to see all chains bootstrap before timeout") } + if flagVars.StartNetwork() { + os.Exit(0) + } + suiteConfig, _ := ginkgo.GinkgoConfiguration() require.Greater( len(network.PreFundedKeys), @@ -214,6 +219,7 @@ func (te *TestEnvironment) StartPrivateNetwork(network *tmpnet.Network) { sharedNetwork.DefaultRuntimeConfig.AvalancheGoPath, pluginDir, te.PrivateNetworkShutdownDelay, + false, /* skipShutdown */ false, /* reuseNetwork */ ) } diff --git a/tests/fixture/e2e/flags.go b/tests/fixture/e2e/flags.go index f87132b0c974..9f791a3ee5ff 100644 --- a/tests/fixture/e2e/flags.go +++ b/tests/fixture/e2e/flags.go @@ -22,6 +22,7 @@ type FlagVars struct { networkDir string reuseNetwork bool delayNetworkShutdown bool + startNetwork bool stopNetwork bool restartNetwork bool nodeCount int @@ -62,6 +63,10 @@ func (v *FlagVars) NetworkShutdownDelay() time.Duration { return 0 } +func (v *FlagVars) StartNetwork() bool { + return v.startNetwork +} + func (v *FlagVars) StopNetwork() bool { return v.stopNetwork } @@ -112,13 +117,13 @@ func RegisterFlags() *FlagVars { &vars.reuseNetwork, "reuse-network", false, - "[optional] reuse an existing network. If an existing network is not already running, create a new one and leave it running for subsequent usage.", + "[optional] reuse an existing network previously started with --reuse-network. If a network is not already running, create a new one and leave it running for subsequent usage. Ignored if --stop-network is provided.", ) flag.BoolVar( &vars.restartNetwork, "restart-network", false, - "[optional] restarts an existing network. Useful for ensuring a network is running with the current state of binaries on disk. Ignored if a network is not already running or --stop-network is provided.", + "[optional] restart an existing network previously started with --reuse-network. Useful for ensuring a network is running with the current state of binaries on disk. Ignored if a network is not already running or --stop-network is provided.", ) flag.BoolVar( &vars.delayNetworkShutdown, @@ -126,11 +131,17 @@ func RegisterFlags() *FlagVars { false, "[optional] whether to delay network shutdown to allow a final metrics scrape.", ) + flag.BoolVar( + &vars.startNetwork, + "start-network", + false, + "[optional] start a new network and exit without executing any tests. The new network cannot be reused with --reuse-network. Ignored if either --reuse-network or --stop-network is provided.", + ) flag.BoolVar( &vars.stopNetwork, "stop-network", false, - "[optional] stop an existing network and exit without executing any tests.", + "[optional] stop an existing network started with --reuse-network and exit without executing any tests.", ) flag.IntVar( &vars.nodeCount, diff --git a/tests/fixture/e2e/helpers.go b/tests/fixture/e2e/helpers.go index 589b5e2a638b..9a088acbbddd 100644 --- a/tests/fixture/e2e/helpers.go +++ b/tests/fixture/e2e/helpers.go @@ -231,6 +231,7 @@ func StartNetwork( avalancheGoExecPath string, pluginDir string, shutdownDelay time.Duration, + skipShutdown bool, reuseNetwork bool, ) { require := require.New(tc) @@ -270,6 +271,11 @@ func StartNetwork( return } + if skipShutdown { + tc.Outf("{{yellow}}Skipping shutdown for network %s{{/}}\n", network.Dir) + return + } + if shutdownDelay > 0 { tc.Outf("Waiting %s before network shutdown to ensure final metrics scrape\n", shutdownDelay) time.Sleep(shutdownDelay) diff --git a/tests/upgrade/upgrade_test.go b/tests/upgrade/upgrade_test.go index 4c0d8fbe79fd..d49684160509 100644 --- a/tests/upgrade/upgrade_test.go +++ b/tests/upgrade/upgrade_test.go @@ -51,7 +51,15 @@ var _ = ginkgo.Describe("[Upgrade]", func() { require.NoError(err) network.Genesis = genesis - e2e.StartNetwork(tc, network, avalancheGoExecPath, "" /* pluginDir */, 0 /* shutdownDelay */, false /* reuseNetwork */) + e2e.StartNetwork( + tc, + network, + avalancheGoExecPath, + "", /* pluginDir */ + 0, /* shutdownDelay */ + false, /* skipShutdown */ + false, /* reuseNetwork */ + ) tc.By(fmt.Sprintf("restarting all nodes with %q binary", avalancheGoExecPathToUpgradeTo)) for _, node := range network.Nodes {