-
Notifications
You must be signed in to change notification settings - Fork 820
e2e: Migrate duplicate node id test from kurtosis #1573
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
13 commits
Select commit
Hold shift + click to select a range
d35b4d7
e2e: Migrate duplicate node id test from kurtosis
maru-ava 74a3299
fixup: Responded to review comments
maru-ava 205e16c
fixup: respond to review feedback #2
maru-ava dce58f6
fixup: respond to review feedback #3
maru-ava 5ccbcc7
fixup: Cleanup ephemeral node implementation
maru-ava d97be31
fixup: Remove unused Node.AddNode method
maru-ava d9b06df
fixup: Revise comment concerning ephemeral node data dir
maru-ava 87814c4
fixup: Address review feedback on comment
maru-ava d196acf
fixup: Make WaitForHealthy a function instead of an Node interface me…
maru-ava 2773caa
fixup: Respond to review comments
maru-ava 80b94e1
fixup: cleanup from rebase
maru-ava b75303e
Update tests/fixture/testnet/local/network.go
maru-ava a39157d
Merge branch 'dev' into e2e-duplicate-nodes
maru-ava 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 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 |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package faultinjection | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| ginkgo "github.com/onsi/ginkgo/v2" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/ava-labs/avalanchego/api/info" | ||
| "github.com/ava-labs/avalanchego/config" | ||
| "github.com/ava-labs/avalanchego/ids" | ||
| "github.com/ava-labs/avalanchego/tests/e2e" | ||
| "github.com/ava-labs/avalanchego/tests/fixture/testnet" | ||
| "github.com/ava-labs/avalanchego/utils/set" | ||
| ) | ||
|
|
||
| var _ = ginkgo.Describe("Duplicate node handling", func() { | ||
| require := require.New(ginkgo.GinkgoT()) | ||
|
|
||
| ginkgo.It("should ensure that a given Node ID (i.e. staking keypair) can be used at most once on a network", func() { | ||
| network := e2e.Env.GetNetwork() | ||
| nodes := network.GetNodes() | ||
|
|
||
| ginkgo.By("creating new node") | ||
| node1 := e2e.AddEphemeralNode(network, testnet.FlagsMap{}) | ||
| e2e.WaitForHealthy(node1) | ||
hexfusion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ginkgo.By("checking that the new node is connected to its peers") | ||
| checkConnectedPeers(nodes, node1) | ||
|
|
||
| ginkgo.By("creating a second new node with the same staking keypair as the first new node") | ||
| node1Flags := node1.GetConfig().Flags | ||
| node2Flags := testnet.FlagsMap{ | ||
| config.StakingTLSKeyContentKey: node1Flags[config.StakingTLSKeyContentKey], | ||
| config.StakingCertContentKey: node1Flags[config.StakingCertContentKey], | ||
| // Construct a unique data dir to ensure the two nodes' data will be stored | ||
| // separately. Usually the dir name is the node ID but in this one case the nodes have | ||
| // the same node ID. | ||
| config.DataDirKey: fmt.Sprintf("%s-second", node1Flags[config.DataDirKey]), | ||
| } | ||
| node2 := e2e.AddEphemeralNode(network, node2Flags) | ||
|
|
||
| ginkgo.By("checking that the second new node fails to become healthy before timeout") | ||
| err := testnet.WaitForHealthy(e2e.DefaultContext(), node2) | ||
| require.ErrorIs(err, context.DeadlineExceeded) | ||
|
|
||
| ginkgo.By("stopping the first new node") | ||
| require.NoError(node1.Stop()) | ||
|
|
||
| ginkgo.By("checking that the second new node becomes healthy within timeout") | ||
| e2e.WaitForHealthy(node2) | ||
|
|
||
| ginkgo.By("checking that the second new node is connected to its peers") | ||
| checkConnectedPeers(nodes, node2) | ||
| }) | ||
| }) | ||
|
|
||
| // Check that a new node is connected to existing nodes and vice versa | ||
| func checkConnectedPeers(existingNodes []testnet.Node, newNode testnet.Node) { | ||
| require := require.New(ginkgo.GinkgoT()) | ||
|
|
||
| // Collect the node ids of the new node's peers | ||
| infoClient := info.NewClient(newNode.GetProcessContext().URI) | ||
| peers, err := infoClient.Peers(context.Background()) | ||
| require.NoError(err) | ||
| peerIDs := set.NewSet[ids.NodeID](len(existingNodes)) | ||
| for _, peer := range peers { | ||
| peerIDs.Add(peer.ID) | ||
| } | ||
|
|
||
| newNodeID := newNode.GetID() | ||
| for _, existingNode := range existingNodes { | ||
| // Check that the existing node is a peer of the new node | ||
| require.True(peerIDs.Contains(existingNode.GetID())) | ||
|
|
||
| // Check that the new node is a peer | ||
| infoClient := info.NewClient(existingNode.GetProcessContext().URI) | ||
| peers, err := infoClient.Peers(context.Background()) | ||
| require.NoError(err) | ||
| isPeer := false | ||
| for _, peer := range peers { | ||
| if peer.ID == newNodeID { | ||
| isPeer = true | ||
| break | ||
| } | ||
| } | ||
| require.True(isPeer) | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package testnet | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "time" | ||
| ) | ||
|
|
||
| const ( | ||
| DefaultNodeTickerInterval = 50 * time.Millisecond | ||
| ) | ||
|
|
||
| var ErrNotRunning = errors.New("not running") | ||
|
|
||
| // WaitForHealthy blocks until Node.IsHealthy returns true or an error (including context timeout) is observed. | ||
| func WaitForHealthy(ctx context.Context, node Node) error { | ||
| if _, ok := ctx.Deadline(); !ok { | ||
| return fmt.Errorf("unable to wait for health for node %q with a context without a deadline", node.GetID()) | ||
| } | ||
| ticker := time.NewTicker(DefaultNodeTickerInterval) | ||
| defer ticker.Stop() | ||
|
|
||
| for { | ||
| healthy, err := node.IsHealthy(ctx) | ||
| if err != nil && !errors.Is(err, ErrNotRunning) { | ||
| return fmt.Errorf("failed to wait for health of node %q: %w", node.GetID(), err) | ||
| } | ||
| if healthy { | ||
| return nil | ||
| } | ||
|
|
||
| select { | ||
| case <-ctx.Done(): | ||
| return fmt.Errorf("failed to wait for health of node %q before timeout: %w", node.GetID(), ctx.Err()) | ||
| case <-ticker.C: | ||
| } | ||
| } | ||
| } |
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
Oops, something went wrong.
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.