Skip to content

Commit 95041b1

Browse files
committed
fixup for final refactor
1 parent fa68cad commit 95041b1

File tree

7 files changed

+55
-39
lines changed

7 files changed

+55
-39
lines changed

Taskfile.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ tasks:
8989
desc: Generates protobuf
9090
cmd: ./scripts/protobuf_codegen.sh
9191

92+
ginkgo-build:
93+
desc: Builds the current directory with ginkgo
94+
cmd: ./scripts/run_ginkgo.sh build {{.USER_WORKING_DIR}} -- {{.CLI_ARGS}}
95+
96+
ginkgo-run:
97+
desc: Tests the current directory with ginkgo
98+
cmd: ./scripts/run_ginkgo.sh -v {{.USER_WORKING_DIR}} -- {{.CLI_ARGS}}
99+
92100
install-nix:
93101
desc: Installs nix with the determinate systems installer
94102
cmd: curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install

tests/e2e/faultinjection/duplicate_node_id.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var _ = ginkgo.Describe("Duplicate node handling", func() {
4444
_ = e2e.AddEphemeralNode(tc, network, node2)
4545

4646
tc.By("checking that the second new node fails to become healthy before timeout")
47-
err := tmpnet.WaitForHealthyNode(tc.DefaultContext(), tc.Log(), node2)
47+
err := node2.WaitForHealthy(tc.DefaultContext())
4848
require.ErrorIs(err, context.DeadlineExceeded)
4949

5050
tc.By("stopping the first new node")

tests/fixture/e2e/helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func WaitForHealthy(tc tests.TestContext, node *tmpnet.Node) {
154154
// Need to use explicit context (vs DefaultContext()) to support use with DeferCleanup
155155
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
156156
defer cancel()
157-
require.NoError(tc, tmpnet.WaitForHealthyNode(ctx, tc.Log(), node))
157+
require.NoError(tc, node.WaitForHealthy(ctx))
158158
}
159159

160160
// Sends an eth transaction and waits for the transaction receipt from the
@@ -248,7 +248,7 @@ func CheckBootstrapIsPossible(tc tests.TestContext, network *tmpnet.Network) *tm
248248
})
249249

250250
// Check that the node becomes healthy within timeout
251-
require.NoError(tmpnet.WaitForHealthyNode(tc.DefaultContext(), tc.Log(), node))
251+
require.NoError(node.WaitForHealthy(tc.DefaultContext()))
252252

253253
// Ensure that the primary validators are still healthy
254254
for _, node := range network.Nodes {

tests/fixture/tmpnet/network.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ var (
6464
// TODO(marun) Remove when subnet-evm configures the genesis with this key.
6565
HardhatKey *secp256k1.PrivateKey
6666

67-
errInsufficientNodes = errors.New("at least one node is required")
67+
errInsufficientNodes = errors.New("at least one node is required")
68+
errMissingRuntimeConfig = errors.New("DefaultRuntimeConfig must not be empty")
6869
)
6970

7071
func init() {
@@ -262,6 +263,11 @@ func (n *Network) EnsureDefaultConfig(log logging.Logger) error {
262263
}
263264
}
264265

266+
emptyRuntime := NodeRuntimeConfig{}
267+
if n.DefaultRuntimeConfig == emptyRuntime {
268+
return errMissingRuntimeConfig
269+
}
270+
265271
return nil
266272
}
267273

@@ -528,7 +534,7 @@ func WaitForHealthyNodes(ctx context.Context, log logging.Logger, nodes ...*Node
528534
log.Info("waiting for node to become healthy",
529535
zap.Stringer("nodeID", node.NodeID),
530536
)
531-
if err := WaitForHealthyNode(ctx, log, node); err != nil {
537+
if err := node.WaitForHealthy(ctx); err != nil {
532538
return err
533539
}
534540
}

tests/fixture/tmpnet/network_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ func TestNetworkSerialization(t *testing.T) {
2020
ctx := context.Background()
2121

2222
network := NewDefaultNetwork("testnet")
23+
// Runtime configuration is required
24+
network.DefaultRuntimeConfig.Process = &ProcessRuntimeConfig{}
2325
// Validate round-tripping of primary subnet configuration
2426
network.PrimarySubnetConfig = ConfigMap{
2527
"validatorOnly": true,

tests/fixture/tmpnet/node.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package tmpnet
66
import (
77
"context"
88
"encoding/base64"
9+
"errors"
910
"fmt"
1011
"io"
1112
"maps"
@@ -16,6 +17,8 @@ import (
1617
"strings"
1718
"time"
1819

20+
"go.uber.org/zap"
21+
1922
"github.com/ava-labs/avalanchego/config"
2023
"github.com/ava-labs/avalanchego/ids"
2124
"github.com/ava-labs/avalanchego/staking"
@@ -412,3 +415,34 @@ func (n *Node) getLabels() map[string]string {
412415
}
413416
return labels
414417
}
418+
419+
// WaitForHealthy blocks until node health is true or an error (including context timeout) is observed.
420+
func (n *Node) WaitForHealthy(ctx context.Context) error {
421+
if _, ok := ctx.Deadline(); !ok {
422+
return fmt.Errorf("unable to wait for health for node %q with a context without a deadline", n.NodeID)
423+
}
424+
ticker := time.NewTicker(DefaultNodeTickerInterval)
425+
defer ticker.Stop()
426+
427+
for {
428+
healthy, err := n.IsHealthy(ctx)
429+
switch {
430+
case errors.Is(err, ErrUnrecoverableNodeHealthCheck):
431+
return fmt.Errorf("%w for node %q", err, n.NodeID)
432+
case err != nil:
433+
n.network.log.Verbo("Failed to query node health",
434+
zap.Stringer("nodeID", n.NodeID),
435+
zap.Error(err),
436+
)
437+
continue
438+
case healthy:
439+
return nil
440+
}
441+
442+
select {
443+
case <-ctx.Done():
444+
return fmt.Errorf("failed to wait for health of node %q before timeout: %w", n.NodeID, ctx.Err())
445+
case <-ticker.C:
446+
}
447+
}
448+
}

tests/fixture/tmpnet/utils.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ import (
1313
"syscall"
1414
"time"
1515

16-
"go.uber.org/zap"
17-
1816
"github.com/ava-labs/avalanchego/api/health"
1917
"github.com/ava-labs/avalanchego/ids"
2018
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
21-
"github.com/ava-labs/avalanchego/utils/logging"
2219
)
2320

2421
const (
@@ -50,37 +47,6 @@ func CheckNodeHealth(ctx context.Context, uri string) (*health.APIReply, error)
5047
return nil, fmt.Errorf("%w: %w", ErrUnrecoverableNodeHealthCheck, err)
5148
}
5249

53-
// WaitForHealthy blocks until Node.IsHealthy returns true or an error (including context timeout) is observed.
54-
func WaitForHealthyNode(ctx context.Context, log logging.Logger, node *Node) error {
55-
if _, ok := ctx.Deadline(); !ok {
56-
return fmt.Errorf("unable to wait for health for node %q with a context without a deadline", node.NodeID)
57-
}
58-
ticker := time.NewTicker(DefaultNodeTickerInterval)
59-
defer ticker.Stop()
60-
61-
for {
62-
healthy, err := node.IsHealthy(ctx)
63-
switch {
64-
case errors.Is(err, ErrUnrecoverableNodeHealthCheck):
65-
return fmt.Errorf("%w for node %q", err, node.NodeID)
66-
case err != nil:
67-
log.Verbo("Failed to query node health",
68-
zap.Stringer("nodeID", node.NodeID),
69-
zap.Error(err),
70-
)
71-
continue
72-
case healthy:
73-
return nil
74-
}
75-
76-
select {
77-
case <-ctx.Done():
78-
return fmt.Errorf("failed to wait for health of node %q before timeout: %w", node.NodeID, ctx.Err())
79-
case <-ticker.C:
80-
}
81-
}
82-
}
83-
8450
// NodeURI associates a node ID with its API URI.
8551
type NodeURI struct {
8652
NodeID ids.NodeID

0 commit comments

Comments
 (0)