Skip to content

Commit 08008bd

Browse files
committed
testing: Switch upgrade test to the testnet fixture
1 parent 2a965fc commit 08008bd

File tree

10 files changed

+153
-201
lines changed

10 files changed

+153
-201
lines changed

.github/workflows/test.upgrade.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ jobs:
2828
run: ./scripts/build.sh
2929
- name: Run upgrade tests
3030
shell: bash
31-
run: scripts/tests.upgrade.sh 1.10.1 ./build/avalanchego
31+
# 1.10.7 is the first version compatible with the testnet
32+
# fixture by virtue of writing a process context file on node
33+
# start.
34+
run: scripts/tests.upgrade.sh 1.10.7 ./build/avalanchego

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ require (
1212
github.com/DataDog/zstd v1.5.2
1313
github.com/Microsoft/go-winio v0.5.2
1414
github.com/NYTimes/gziphandler v1.1.1
15-
github.com/ava-labs/avalanche-network-runner-sdk v0.3.0
1615
github.com/ava-labs/coreth v0.12.5-rc.1.0.20230814185807-00214b143a8a
1716
github.com/ava-labs/ledger-avalanche/go v0.0.0-20230105152938-00a24d05a8c7
1817
github.com/btcsuite/btcd/btcutil v1.1.3

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah
6161
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
6262
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
6363
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
64-
github.com/ava-labs/avalanche-network-runner-sdk v0.3.0 h1:TVi9JEdKNU/RevYZ9PyW4pULbEdS+KQDA9Ki2DUvuAs=
65-
github.com/ava-labs/avalanche-network-runner-sdk v0.3.0/go.mod h1:SgKJvtqvgo/Bl/c8fxEHCLaSxEbzimYfBopcfrajxQk=
6664
github.com/ava-labs/coreth v0.12.5-rc.1.0.20230814185807-00214b143a8a h1:WNZDFqolp4rumlJVzJ92hl9VDkL904yIQFd7CmBr3rk=
6765
github.com/ava-labs/coreth v0.12.5-rc.1.0.20230814185807-00214b143a8a/go.mod h1:K7Xm2jqx90wxKZXfLvkLEL+zlM5843gGq9XkqVDwKds=
6866
github.com/ava-labs/ledger-avalanche/go v0.0.0-20230105152938-00a24d05a8c7 h1:EdxD90j5sClfL5Ngpz2TlnbnkNYdFPDXa0jDOjam65c=

scripts/install_anr.sh

Lines changed: 0 additions & 34 deletions
This file was deleted.

scripts/tests.upgrade.sh

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ elif [[ ${GOOS} == "darwin" ]]; then
5252
fi
5353
find /tmp/avalanchego-v${VERSION}
5454

55-
#################################
56-
echo "installing avalanche-network-runner"
57-
ANR_WORKDIR="/tmp"
58-
./scripts/install_anr.sh
59-
6055
# Sourcing constants.sh ensures that the necessary CGO flags are set to
6156
# build the portable version of BLST. Without this, ginkgo may fail to
6257
# build the test binary if run on a host (e.g. github worker) that lacks
@@ -70,31 +65,14 @@ go install -v github.com/onsi/ginkgo/v2/ginkgo@v2.1.4
7065
ACK_GINKGO_RC=true ginkgo build ./tests/upgrade
7166
./tests/upgrade/upgrade.test --help
7267

73-
#################################
74-
# run "avalanche-network-runner" server
75-
echo "launch avalanche-network-runner in the background"
76-
$ANR_WORKDIR/avalanche-network-runner \
77-
server \
78-
--log-level debug \
79-
--port=":12340" \
80-
--disable-grpc-gateway &
81-
PID=${!}
82-
8368
#################################
8469
# By default, it runs all upgrade test cases!
8570
echo "running upgrade tests against the local cluster with ${NEW_BINARY}"
8671
./tests/upgrade/upgrade.test \
8772
--ginkgo.v \
88-
--log-level debug \
89-
--network-runner-grpc-endpoint="0.0.0.0:12340" \
90-
--network-runner-avalanchego-path=/tmp/avalanchego-v${VERSION}/avalanchego \
91-
--network-runner-avalanchego-path-to-upgrade=${NEW_BINARY} \
92-
--network-runner-avalanchego-log-level="WARN" || EXIT_CODE=$?
93-
94-
# "e2e.test" already terminates the cluster
95-
# just in case tests are aborted, manually terminate them again
96-
pkill -P ${PID} || true
97-
kill -2 ${PID}
73+
--avalanchego-path=/tmp/avalanchego-v${VERSION}/avalanchego \
74+
--avalanchego-path-to-upgrade-to=${NEW_BINARY} \
75+
|| EXIT_CODE=$?
9876

9977
if [[ "${EXIT_CODE:-}" -gt 0 ]]; then
10078
echo "FAILURE with exit code ${EXIT_CODE}"

tests/e2e/e2e.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
"context"
99
"encoding/json"
1010
"math/rand"
11+
"os"
12+
"os/exec"
13+
"path/filepath"
1114
"time"
1215

1316
ginkgo "github.com/onsi/ginkgo/v2"
@@ -111,3 +114,54 @@ func (te *TestEnvironment) NewWallet(keychain *secp256k1fx.Keychain) primary.Wal
111114
te.require.NoError(err)
112115
return wallet
113116
}
117+
118+
// Start a local test-managed network with the provided avalanchego binary.
119+
func StartLocalNetwork(avalancheGoExecPath string, archiveNetworkDir bool) *local.LocalNetwork {
120+
require := require.New(ginkgo.GinkgoT())
121+
122+
tests.Outf("{{magenta}}Starting network with %q{{/}}\n", avalancheGoExecPath)
123+
124+
var networkRootDir string
125+
if archiveNetworkDir {
126+
// Since the network dir will be archived on teardown, cleaning up the
127+
// directory won't prevent troubleshooting.
128+
networkRootDir = ginkgo.GinkgoT().TempDir()
129+
} else {
130+
// Use a temp directory that will not be removed on teardown to aid in
131+
// troubleshooting.
132+
var err error
133+
networkRootDir, err = os.MkdirTemp("", "networks")
134+
require.NoError(err)
135+
}
136+
137+
ctx, cancel := context.WithTimeout(context.Background(), local.DefaultNetworkStartTimeout)
138+
defer cancel()
139+
network, err := local.StartNetwork(
140+
ctx,
141+
ginkgo.GinkgoWriter,
142+
networkRootDir,
143+
&local.LocalNetwork{
144+
LocalConfig: local.LocalConfig{
145+
ExecPath: avalancheGoExecPath,
146+
},
147+
},
148+
testnet.DefaultNodeCount,
149+
testnet.DefaultFundedKeyCount,
150+
)
151+
require.NoError(err)
152+
ginkgo.DeferCleanup(func() {
153+
tests.Outf("Shutting down network\n")
154+
require.NoError(network.Stop())
155+
if archiveNetworkDir {
156+
scriptPath, err := filepath.Abs("../../scripts/archive_network_dir.sh")
157+
require.NoError(err)
158+
output, err := exec.Command(scriptPath, network.Dir).Output()
159+
require.NoError(err)
160+
tests.Outf("%s", output)
161+
}
162+
})
163+
164+
tests.Outf("{{green}}Successfully started network{{/}}\n")
165+
166+
return network
167+
}

tests/e2e/e2e_test.go

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
package e2e_test
55

66
import (
7-
"context"
87
"encoding/json"
98
"flag"
109
"fmt"
1110
"os"
12-
"os/exec"
13-
"path/filepath"
1411
"testing"
1512

1613
ginkgo "github.com/onsi/ginkgo/v2"
@@ -22,7 +19,6 @@ import (
2219
"github.com/ava-labs/avalanchego/tests"
2320
"github.com/ava-labs/avalanchego/tests/e2e"
2421
"github.com/ava-labs/avalanchego/tests/fixture"
25-
"github.com/ava-labs/avalanchego/tests/fixture/testnet"
2622
"github.com/ava-labs/avalanchego/tests/fixture/testnet/local"
2723

2824
// ensure test packages are scanned by ginkgo
@@ -97,37 +93,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
9793
network, err = local.ReadNetwork(persistentNetworkDir)
9894
require.NoError(err)
9995
} else {
100-
tests.Outf("{{magenta}}Starting network with %q{{/}}\n", avalancheGoExecPath)
101-
102-
ctx, cancel := context.WithTimeout(context.Background(), local.DefaultNetworkStartTimeout)
103-
defer cancel()
104-
var err error
105-
network, err = local.StartNetwork(
106-
ctx,
107-
ginkgo.GinkgoWriter,
108-
ginkgo.GinkgoT().TempDir(),
109-
&local.LocalNetwork{
110-
LocalConfig: local.LocalConfig{
111-
ExecPath: avalancheGoExecPath,
112-
},
113-
},
114-
testnet.DefaultNodeCount,
115-
testnet.DefaultFundedKeyCount,
116-
)
117-
require.NoError(err)
118-
ginkgo.DeferCleanup(func() {
119-
tests.Outf("Shutting down network\n")
120-
require.NoError(network.Stop())
121-
if archiveNetworkDirOnTeardown {
122-
scriptPath, err := filepath.Abs("../../scripts/archive_network_dir.sh")
123-
require.NoError(err)
124-
output, err := exec.Command(scriptPath, network.Dir).Output()
125-
require.NoError(err)
126-
tests.Outf("%s", output)
127-
}
128-
})
129-
130-
tests.Outf("{{green}}Successfully started network{{/}}\n")
96+
network = e2e.StartLocalNetwork(avalancheGoExecPath, archiveNetworkDirOnTeardown)
13197
}
13298

13399
uris := network.GetURIs()

tests/fixture/testnet/local/network.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,22 @@ func (ln *LocalNetwork) ReadAll() error {
632632
}
633633
return ln.ReadNodes()
634634
}
635+
636+
func (ln *LocalNetwork) GetBootstrapIPsAndIds() ([]string, []string, error) {
637+
// Collect staking addresses of running nodes for use in bootstrapping a node
638+
if err := ln.ReadNodes(); err != nil {
639+
return nil, nil, fmt.Errorf("failed to read local network nodes: %w", err)
640+
}
641+
bootstrapIPs := make([]string, 0, len(ln.Nodes))
642+
bootstrapIDs := make([]string, 0, len(ln.Nodes))
643+
for _, node := range ln.Nodes {
644+
if len(node.StakingAddress) == 0 {
645+
// Node is not running
646+
continue
647+
}
648+
649+
bootstrapIPs = append(bootstrapIPs, node.StakingAddress)
650+
bootstrapIDs = append(bootstrapIDs, node.NodeID.String())
651+
}
652+
return bootstrapIPs, bootstrapIDs, nil
653+
}

tests/fixture/testnet/local/node.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,31 @@ func (n *LocalNode) IsHealthy(ctx context.Context) (bool, error) {
311311
return false, err
312312
}
313313

314+
// WaitForHealthy blocks until IsHealthy returns true or an error (including context timeout) is observed.
315+
func (n *LocalNode) WaitForHealthy(ctx context.Context) error {
316+
if _, ok := ctx.Deadline(); !ok {
317+
return fmt.Errorf("unable to wait for health for node %q with a context without a deadline", n.NodeID)
318+
}
319+
ticker := time.NewTicker(DefaultNodeTickerInterval)
320+
defer ticker.Stop()
321+
322+
for {
323+
healthy, err := n.IsHealthy(ctx)
324+
if err != nil && !errors.Is(err, errProcessNotRunning) {
325+
return fmt.Errorf("failed to wait for health of node %q: %w", n.NodeID, err)
326+
}
327+
if healthy {
328+
return nil
329+
}
330+
331+
select {
332+
case <-ctx.Done():
333+
return fmt.Errorf("failed to wait for health of node %q before timeout: %w", n.NodeID, ctx.Err())
334+
case <-ticker.C:
335+
}
336+
}
337+
}
338+
314339
func (n *LocalNode) WaitForProcessContext(ctx context.Context) error {
315340
ticker := time.NewTicker(DefaultNodeTickerInterval)
316341
defer ticker.Stop()

0 commit comments

Comments
 (0)