-
Notifications
You must be signed in to change notification settings - Fork 807
testing: Switch upgrade test to testnet fixture #1887
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,143 +1,80 @@ | ||
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
// Runs upgrade tests. | ||
package upgrade_test | ||
package upgrade | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
|
||
"github.com/onsi/gomega" | ||
|
||
runner_sdk "github.com/ava-labs/avalanche-network-runner-sdk" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ava-labs/avalanchego/tests" | ||
"github.com/ava-labs/avalanchego/config" | ||
"github.com/ava-labs/avalanchego/tests/e2e" | ||
) | ||
|
||
const DefaultTimeout = 2 * time.Minute | ||
|
||
func TestUpgrade(t *testing.T) { | ||
gomega.RegisterFailHandler(ginkgo.Fail) | ||
ginkgo.RunSpecs(t, "upgrade test suites") | ||
} | ||
|
||
var ( | ||
logLevel string | ||
networkRunnerGRPCEp string | ||
networkRunnerAvalancheGoExecPath string | ||
networkRunnerAvalancheGoExecPathToUpgrade string | ||
networkRunnerAvalancheGoLogLevel string | ||
avalancheGoExecPath string | ||
avalancheGoExecPathToUpgradeTo string | ||
) | ||
|
||
func init() { | ||
flag.StringVar( | ||
&logLevel, | ||
"log-level", | ||
"info", | ||
"log level", | ||
) | ||
flag.StringVar( | ||
&networkRunnerGRPCEp, | ||
"network-runner-grpc-endpoint", | ||
"", | ||
"gRPC server endpoint for network-runner", | ||
) | ||
flag.StringVar( | ||
&networkRunnerAvalancheGoExecPath, | ||
"network-runner-avalanchego-path", | ||
&avalancheGoExecPath, | ||
"avalanchego-path", | ||
"", | ||
"avalanchego executable path", | ||
) | ||
flag.StringVar( | ||
&networkRunnerAvalancheGoExecPathToUpgrade, | ||
"network-runner-avalanchego-path-to-upgrade", | ||
&avalancheGoExecPathToUpgradeTo, | ||
"avalanchego-path-to-upgrade-to", | ||
"", | ||
"avalanchego executable path (to upgrade to, only required for upgrade tests with local network-runner)", | ||
) | ||
flag.StringVar( | ||
&networkRunnerAvalancheGoLogLevel, | ||
"network-runner-avalanchego-log-level", | ||
"INFO", | ||
"avalanchego log-level", | ||
"avalanchego executable path to upgrade to", | ||
) | ||
} | ||
|
||
var runnerCli runner_sdk.Client | ||
|
||
var _ = ginkgo.BeforeSuite(func() { | ||
_, err := os.Stat(networkRunnerAvalancheGoExecPath) | ||
gomega.Expect(err).Should(gomega.BeNil()) | ||
|
||
_, err = os.Stat(networkRunnerAvalancheGoExecPathToUpgrade) | ||
gomega.Expect(err).Should(gomega.BeNil()) | ||
|
||
runnerCli, err = runner_sdk.New(runner_sdk.Config{ | ||
LogLevel: logLevel, | ||
Endpoint: networkRunnerGRPCEp, | ||
DialTimeout: 10 * time.Second, | ||
}) | ||
gomega.Expect(err).Should(gomega.BeNil()) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout) | ||
presp, err := runnerCli.Ping(ctx) | ||
cancel() | ||
gomega.Expect(err).Should(gomega.BeNil()) | ||
tests.Outf("{{green}}network-runner running in PID %d{{/}}\n", presp.Pid) | ||
|
||
tests.Outf("{{magenta}}starting network-runner with %q{{/}}\n", networkRunnerAvalancheGoExecPath) | ||
ctx, cancel = context.WithTimeout(context.Background(), DefaultTimeout) | ||
resp, err := runnerCli.Start(ctx, networkRunnerAvalancheGoExecPath, | ||
runner_sdk.WithNumNodes(5), | ||
runner_sdk.WithGlobalNodeConfig(fmt.Sprintf(`{"log-level":"%s"}`, networkRunnerAvalancheGoLogLevel)), | ||
) | ||
cancel() | ||
gomega.Expect(err).Should(gomega.BeNil()) | ||
tests.Outf("{{green}}successfully started network-runner: {{/}} %+v\n", resp.ClusterInfo.NodeNames) | ||
|
||
ctx, cancel = context.WithTimeout(context.Background(), DefaultTimeout) | ||
_, err = runnerCli.Health(ctx) | ||
cancel() | ||
gomega.Expect(err).Should(gomega.BeNil()) | ||
}) | ||
|
||
var _ = ginkgo.AfterSuite(func() { | ||
tests.Outf("{{red}}shutting down network-runner cluster{{/}}\n") | ||
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout) | ||
_, err := runnerCli.Stop(ctx) | ||
cancel() | ||
gomega.Expect(err).Should(gomega.BeNil()) | ||
|
||
tests.Outf("{{red}}shutting down network-runner client{{/}}\n") | ||
err = runnerCli.Close() | ||
gomega.Expect(err).Should(gomega.BeNil()) | ||
}) | ||
|
||
var _ = ginkgo.Describe("[Upgrade]", func() { | ||
require := require.New(ginkgo.GinkgoT()) | ||
|
||
ginkgo.It("can upgrade versions", func() { | ||
tests.Outf("{{magenta}}starting upgrade tests %q{{/}}\n", networkRunnerAvalancheGoExecPathToUpgrade) | ||
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout) | ||
sresp, err := runnerCli.Status(ctx) | ||
cancel() | ||
gomega.Expect(err).Should(gomega.BeNil()) | ||
|
||
for _, name := range sresp.ClusterInfo.NodeNames { | ||
tests.Outf("{{magenta}}restarting the node %q{{/}} with %q\n", name, networkRunnerAvalancheGoExecPathToUpgrade) | ||
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout) | ||
resp, err := runnerCli.RestartNode(ctx, name, runner_sdk.WithExecPath(networkRunnerAvalancheGoExecPathToUpgrade)) | ||
cancel() | ||
gomega.Expect(err).Should(gomega.BeNil()) | ||
|
||
ctx, cancel = context.WithTimeout(context.Background(), DefaultTimeout) | ||
_, err = runnerCli.Health(ctx) | ||
cancel() | ||
gomega.Expect(err).Should(gomega.BeNil()) | ||
tests.Outf("{{green}}successfully upgraded %q to %q{{/}} (current info: %+v)\n", name, networkRunnerAvalancheGoExecPathToUpgrade, resp.ClusterInfo.NodeInfos) | ||
// TODO(marun) How many nodes should the target network have to best validate upgrade? | ||
network := e2e.StartLocalNetwork(avalancheGoExecPath, e2e.DefaultNetworkDir) | ||
|
||
ginkgo.By(fmt.Sprintf("restarting all nodes with %q binary", avalancheGoExecPathToUpgradeTo)) | ||
for _, node := range network.Nodes { | ||
ginkgo.By(fmt.Sprintf("restarting node %q with %q binary", node.GetID(), avalancheGoExecPathToUpgradeTo)) | ||
require.NoError(node.Stop()) | ||
|
||
// A node must start with sufficient bootstrap nodes to represent a quorum. Since the node's current | ||
// bootstrap configuration may not satisfy this requirement (i.e. if on network start the node was one of | ||
// the first validators), updating the node to bootstrap from all running validators maximizes the | ||
// chances of a successful start. | ||
// | ||
// TODO(marun) Refactor node start to do this automatically | ||
bootstrapIPs, bootstrapIDs, err := network.GetBootstrapIPsAndIDs() | ||
require.NoError(err) | ||
require.NotEmpty(bootstrapIDs) | ||
node.Flags[config.BootstrapIDsKey] = strings.Join(bootstrapIDs, ",") | ||
node.Flags[config.BootstrapIPsKey] = strings.Join(bootstrapIPs, ",") | ||
require.NoError(node.WriteConfig()) | ||
|
||
require.NoError(node.Start(ginkgo.GinkgoWriter, avalancheGoExecPath)) | ||
|
||
ginkgo.By(fmt.Sprintf("waiting for node %q to report healthy after restart", node.GetID())) | ||
e2e.WaitForHealthy(node) | ||
} | ||
|
||
e2e.CheckBootstrapIsPossible(network) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.