-
Notifications
You must be signed in to change notification settings - Fork 807
e2e: Add local network fixture #1700
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
38 commits
Select commit
Hold shift + click to select a range
c326b18
e2e: Add local network fixture
maru-ava c2ded4a
fixup: self-review cleanup
maru-ava af4c8d0
fixup: Respond to review feedback
maru-ava efb986a
fixup: More responding to review feedback
maru-ava 10a4a94
fixup: Don't treat 'process already finished' as error on node stop
maru-ava 72a5bb2
fixup: Switch from SIGKILL to SIGTERM to stop nodes
maru-ava 517e203
fixup: respond to review comments 3
maru-ava baa4cad
fixup: Use a more descriptive name for node init timeout const
maru-ava d81cc17
fixup: Fix truncated function comment.
maru-ava 48d4f85
fixup: respond to review feedback 4
maru-ava bc150c2
fixup: respond to review feedback 5
maru-ava c900e54
fixup: respond to review feedback 6
maru-ava 1fc22c8
fixup: Refactor process liveness checks
maru-ava fdf0f9f
fixup: Fix the use of testnetctl --use-static-ports
maru-ava ebf3dc2
fixup: Ensure testing of static node ports in persistent network job
maru-ava 19a5bff
fixup: Always use process context file to synchronize node start
maru-ava 5df110b
fixup: Define err constant for static error
maru-ava ce5114d
fixup: wrap error instead of just printing it
maru-ava e48b861
fixup: respond to review comments 7.
maru-ava 0422ea2
fixup: use WaitForProcessContext in Start to indicate start success
maru-ava af878b6
fixup: respond to review feedback 8
maru-ava dbac5fd
fixup: Add version command to testnetctl
maru-ava b3fedc6
fixup: Remove support for static ports
maru-ava 9eb7cca
fixup: respond to review comments 9
maru-ava 49cfe52
fixup: Remove unused constant
maru-ava 5fa29ca
Update .github/workflows/test.e2e.persistent.yml
maru-ava 932c2a0
Update tests/fixture/testnet/cmd/main.go
maru-ava afb9f55
Update tests/fixture/testnet/cmd/main.go
maru-ava 4ff6dd6
Update tests/fixture/testnet/cmd/main.go
maru-ava e8d4a75
Update tests/fixture/testnet/local/node.go
maru-ava 8ca9cdf
Update tests/fixture/testnet/local/node_test.go
maru-ava 744be0c
Update tests/fixture/testnet/local/network_test.go
maru-ava 533e896
Update tests/fixture/testnet/local/README.md
maru-ava 643ce4b
fixup: Respond to review comments 10
maru-ava 4f93b42
fixup: lint errors
maru-ava bf49c01
fixup: Add TODO comment about X-Chain and P-Chain configuration
maru-ava 2cb928d
Remove unnecessary import alias
StephenButtolph 0044324
Merge branch 'dev' into e2e-local-network
StephenButtolph 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Test e2e with persistent network | ||
|
||
on: | ||
push: | ||
tags: | ||
- "*" | ||
branches: | ||
- master | ||
- dev | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test_e2e_persistent: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '~1.19.12' | ||
check-latest: true | ||
- name: Build the avalanchego binary | ||
shell: bash | ||
run: ./scripts/build.sh -r | ||
- name: Run e2e tests with persistent network | ||
shell: bash | ||
run: ./scripts/tests.e2e.persistent.sh ./build/avalanchego |
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
Large diffs are not rendered by default.
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
marun marked this conversation as resolved.
Show resolved
Hide resolved
|
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,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
# Avalanchego root folder | ||
AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) | ||
# Load the constants | ||
source "$AVALANCHE_PATH"/scripts/constants.sh | ||
|
||
echo "Building testnetctl..." | ||
go build -ldflags\ | ||
"-X github.com/ava-labs/avalanchego/version.GitCommit=$git_commit $static_ld_flags"\ | ||
marun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-o "$AVALANCHE_PATH/build/testnetctl"\ | ||
"$AVALANCHE_PATH/tests/fixture/testnet/cmd/"*.go |
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,64 @@ | ||
#!/usr/bin/env bash | ||
marun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
set -e | ||
marun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
set -o nounset | ||
set -o pipefail | ||
|
||
################################################################ | ||
# This script deploys a persistent local network and configures | ||
StephenButtolph marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# tests.e2e.sh to execute the e2e suite against it. | ||
################################################################ | ||
|
||
# e.g., | ||
# ./scripts/build.sh | ||
# ./scripts/tests.e2e.persistent_network.sh ./build/avalanchego | ||
if ! [[ "$0" =~ scripts/tests.e2e.persistent.sh ]]; then | ||
echo "must be run from repository root" | ||
exit 255 | ||
fi | ||
|
||
AVALANCHEGO_PATH="${1-${AVALANCHEGO_PATH:-}}" | ||
if [[ -z "${AVALANCHEGO_PATH}" ]]; then | ||
echo "Missing AVALANCHEGO_PATH argument!" | ||
echo "Usage: ${0} [AVALANCHEGO_PATH]" >>/dev/stderr | ||
exit 255 | ||
fi | ||
# Ensure an absolute path to avoid dependency on the working directory | ||
# of script execution. | ||
export AVALANCHEGO_PATH="$(realpath ${AVALANCHEGO_PATH})" | ||
marun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Create a temporary directory to store persistent network | ||
ROOT_DIR="$(mktemp -d -t e2e-testnet.XXXXX)" | ||
hexfusion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Provide visual separation between testing and setup/teardown | ||
function print_separator { | ||
printf '%*s\n' "${COLUMNS:-80}" '' | tr ' ' ─ | ||
} | ||
|
||
# Ensure network cleanup on teardown | ||
function cleanup { | ||
print_separator | ||
echo "cleaning up persistent network" | ||
if [[ -n "${TESTNETCTL_NETWORK_DIR:-}" ]]; then | ||
./build/testnetctl stop-network | ||
fi | ||
rm -r "${ROOT_DIR}" | ||
} | ||
trap cleanup EXIT | ||
|
||
# Start a persistent network | ||
./scripts/build_testnetctl.sh | ||
print_separator | ||
./build/testnetctl start-network --root-dir="${ROOT_DIR}" | ||
|
||
# Determine the network configuration path from the latest symlink | ||
LATEST_SYMLINK_PATH="${ROOT_DIR}/latest" | ||
felipemadero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if [[ -h "${LATEST_SYMLINK_PATH}" ]]; then | ||
export TESTNETCTL_NETWORK_DIR="$(realpath ${LATEST_SYMLINK_PATH})" | ||
else | ||
echo "failed to find configuration path: ${LATEST_SYMLINK_PATH} symlink not found" | ||
exit 255 | ||
fi | ||
|
||
print_separator | ||
# TODO(marun) Enable e2e testing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to run tests.e2e.sh in #1709 |
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,8 @@ | ||
# Test Network Fixture | ||
|
||
This package contains configuration and interfaces that are | ||
independent of a given orchestration mechanism | ||
(e.g. [local](local/README.md)). The intent is to enable tests to be | ||
written against the interfaces defined in this package and for | ||
implementation-specific details of test network orchestration to be | ||
limited to test setup and teardown. |
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,124 @@ | ||
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. | ||
marun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// See the file LICENSE for licensing terms. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/ava-labs/avalanchego/tests/fixture/testnet" | ||
"github.com/ava-labs/avalanchego/tests/fixture/testnet/local" | ||
"github.com/ava-labs/avalanchego/version" | ||
) | ||
|
||
const cliVersion = "0.0.1" | ||
|
||
var ( | ||
errAvalancheGoRequired = fmt.Errorf("--avalanchego-path or %s are required", local.AvalancheGoPathEnvName) | ||
errNetworkDirRequired = fmt.Errorf("--network-dir or %s are required", local.NetworkDirEnvName) | ||
) | ||
|
||
func main() { | ||
marun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rootCmd := &cobra.Command{ | ||
Use: "testnetctl", | ||
Short: "testnetctl commands", | ||
} | ||
|
||
versionCmd := &cobra.Command{ | ||
Use: "version", | ||
Short: "Print version details", | ||
RunE: func(*cobra.Command, []string) error { | ||
msg := cliVersion | ||
if len(version.GitCommit) > 0 { | ||
msg += ", commit=" + version.GitCommit | ||
} | ||
fmt.Fprintf(os.Stdout, msg+"\n") | ||
return nil | ||
}, | ||
} | ||
rootCmd.AddCommand(versionCmd) | ||
|
||
var ( | ||
rootDir string | ||
execPath string | ||
nodeCount uint8 | ||
fundedKeyCount uint8 | ||
) | ||
startNetworkCmd := &cobra.Command{ | ||
Use: "start-network", | ||
Short: "Start a new local network", | ||
RunE: func(*cobra.Command, []string) error { | ||
if len(execPath) == 0 { | ||
felipemadero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return errAvalancheGoRequired | ||
} | ||
|
||
// Root dir will be defaulted on start if not provided | ||
|
||
network := &local.LocalNetwork{ | ||
LocalConfig: local.LocalConfig{ | ||
ExecPath: execPath, | ||
}, | ||
} | ||
ctx, cancel := context.WithTimeout(context.Background(), local.DefaultNetworkStartTimeout) | ||
defer cancel() | ||
network, err := local.StartNetwork(ctx, os.Stdout, rootDir, network, int(nodeCount), int(fundedKeyCount)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Symlink the new network to the 'latest' network to simplify usage | ||
networkRootDir := filepath.Dir(network.Dir) | ||
networkDirName := filepath.Base(network.Dir) | ||
latestSymlinkPath := filepath.Join(networkRootDir, "latest") | ||
if err := os.Remove(latestSymlinkPath); err != nil && !errors.Is(err, fs.ErrNotExist) { | ||
return err | ||
} | ||
if err := os.Symlink(networkDirName, latestSymlinkPath); err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(os.Stdout, "\nConfigure testnetctl to target this network by default with one of the following statements:") | ||
fmt.Fprintf(os.Stdout, "\n - source %s\n", network.EnvFilePath()) | ||
fmt.Fprintf(os.Stdout, " - %s\n", network.EnvFileContents()) | ||
fmt.Fprintf(os.Stdout, " - export %s=%s\n", local.NetworkDirEnvName, latestSymlinkPath) | ||
|
||
return nil | ||
}, | ||
} | ||
startNetworkCmd.PersistentFlags().StringVar(&rootDir, "root-dir", os.Getenv(local.RootDirEnvName), "The path to the root directory for local networks") | ||
startNetworkCmd.PersistentFlags().StringVar(&execPath, "avalanchego-path", os.Getenv(local.AvalancheGoPathEnvName), "The path to an avalanchego binary") | ||
startNetworkCmd.PersistentFlags().Uint8Var(&nodeCount, "node-count", testnet.DefaultNodeCount, "Number of nodes the network should initially consist of") | ||
startNetworkCmd.PersistentFlags().Uint8Var(&fundedKeyCount, "funded-key-count", testnet.DefaultFundedKeyCount, "Number of funded keys the network should start with") | ||
rootCmd.AddCommand(startNetworkCmd) | ||
|
||
var networkDir string | ||
stopNetworkCmd := &cobra.Command{ | ||
Use: "stop-network", | ||
Short: "Stop a local network", | ||
RunE: func(*cobra.Command, []string) error { | ||
if len(networkDir) == 0 { | ||
felipemadero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return errNetworkDirRequired | ||
} | ||
if err := local.StopNetwork(networkDir); err != nil { | ||
return err | ||
} | ||
fmt.Fprintf(os.Stdout, "Stopped network configured at: %s\n", networkDir) | ||
return nil | ||
}, | ||
} | ||
stopNetworkCmd.PersistentFlags().StringVar(&networkDir, "network-dir", os.Getenv(local.NetworkDirEnvName), "The path to the configuration directory of a local network") | ||
rootCmd.AddCommand(stopNetworkCmd) | ||
|
||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Fprintf(os.Stderr, "testnetctl failed: %v\n", err) | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
} |
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.