Skip to content

Commit

Permalink
[tmpnet] Enable network restart to simplify iteration (#3272)
Browse files Browse the repository at this point in the history
  • Loading branch information
marun authored Aug 7, 2024
1 parent 9b34a2d commit 6626d2b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ If a network is not already running the first time the suite runs with
`--reuse-network`, one will be started automatically and configured
for reuse by subsequent test runs also supplying `--reuse-network`.

### Restarting temporary networks

When iterating on a change to avalanchego and/or a VM, it may be
useful to restart a running network to ensure the network is using the
latest binary state. Supplying `--restart-network` in addition to
`--reuse-network` will ensure that all nodes are restarted before
tests are run. `--restart-network` is ignored if a network is not
running or if `--stop-network` is supplied.

### Stopping temporary networks

To stop a network configured for reuse, invoke the test suite with the
`--stop-network` argument. This will stop the network and exit
immediately without executing any tests:
Expand Down
3 changes: 3 additions & 0 deletions tests/fixture/e2e/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func NewTestEnvironment(tc tests.TestContext, flagVars *FlagVars, desiredNetwork
tc.Outf("No network to stop\n")
}
os.Exit(0)
} else if network != nil && flagVars.RestartNetwork() {
// A network is only restarted if it is already running and stop was not requested
require.NoError(network.Restart(tc.DefaultContext(), tc.GetWriter()))
}
}

Expand Down
11 changes: 11 additions & 0 deletions tests/fixture/e2e/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type FlagVars struct {
reuseNetwork bool
delayNetworkShutdown bool
stopNetwork bool
restartNetwork bool
nodeCount int
activateEtna bool
}
Expand All @@ -45,6 +46,10 @@ func (v *FlagVars) ReuseNetwork() bool {
return v.reuseNetwork
}

func (v *FlagVars) RestartNetwork() bool {
return v.restartNetwork
}

func (v *FlagVars) NetworkShutdownDelay() time.Duration {
if v.delayNetworkShutdown {
// Only return a non-zero value if the delay is enabled. Make sure this value takes
Expand Down Expand Up @@ -92,6 +97,12 @@ func RegisterFlags() *FlagVars {
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.",
)
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.",
)
flag.BoolVar(
&vars.delayNetworkShutdown,
"delay-network-shutdown",
Expand Down

0 comments on commit 6626d2b

Please sign in to comment.