Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions graft/subnet-evm/tests/load/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
package load

import (
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"

Expand All @@ -30,11 +32,20 @@ const (
subnetAName = "load-subnet-a"
)

var flagVars *e2e.FlagVars
var (
flagVars *e2e.FlagVars
repoRootPath string
)

func init() {
// Configures flags used to configure tmpnet
flagVars = e2e.RegisterFlags()
flag.StringVar(
&repoRootPath,
"repo-root",
"",
"absolute path to the repository root (required if scripts cannot be found via relative paths)",
)
}

func TestE2E(t *testing.T) {
Expand All @@ -45,16 +56,20 @@ var _ = ginkgo.Describe("[Load Simulator]", ginkgo.Ordered, func() {
require := require.New(ginkgo.GinkgoT())

var (
env *e2e.TestEnvironment
repoRoot string
env *e2e.TestEnvironment
scriptPath string
)

ginkgo.BeforeAll(func() {
tc := e2e.NewTestContext()

var err error
repoRoot, err = e2e.GetRepoRootPath("tests/load")
require.NoError(err)
scriptPath = filepath.Join("..", "..", "scripts", "run_simulator.sh")
if _, err := os.Stat(scriptPath); err != nil {
if repoRootPath != "" {
scriptPath = filepath.Join(repoRootPath, "scripts", "run_simulator.sh")
}
require.NoError(err, "failed to locate run_simulator.sh - try specifying -repo-root flag")
}

nodes := utils.NewTmpnetNodes(nodeCount)
env = e2e.NewTestEnvironment(
Expand Down Expand Up @@ -90,8 +105,7 @@ var _ = ginkgo.Describe("[Load Simulator]", ginkgo.Ordered, func() {
require.NoError(os.Setenv("RPC_ENDPOINTS", commaSeparatedRPCEndpoints))

log.Info("Running load simulator...", "rpcEndpoints", commaSeparatedRPCEndpoints)
cmd := exec.Command("./scripts/run_simulator.sh")
cmd.Dir = repoRoot
cmd := exec.Command(scriptPath)
log.Info("Running load simulator script", "cmd", cmd.String())

out, err := cmd.CombinedOutput()
Expand Down
23 changes: 15 additions & 8 deletions tests/fixture/bootstrapmonitor/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ func TestE2E(t *testing.T) {
}

const (
// The relative path to the repo root enables discovery of the
// repo root when the test is executed from the root or the path
// of this file.
repoRelativePath = "tests/fixture/bootstrapmonitor/e2e"

avalanchegoImage = "localhost:5001/avalanchego"
masterAvalanchegoImage = avalanchegoImage + ":master"
monitorImage = "localhost:5001/bootstrap-monitor"
Expand All @@ -65,6 +60,7 @@ var (
kubeconfigVars *flags.KubeconfigVars
skipAvalanchegoImageBuild bool
skipMonitorImageBuild bool
repoRootPath string

nodeDataDir = bootstrapmonitor.NodeDataDir(dataDir) // Use a subdirectory of the data path so that os.RemoveAll can be used when starting a new test
)
Expand All @@ -83,6 +79,12 @@ func init() {
false,
"whether to skip building the bootstrap-monitor image",
)
flag.StringVar(
&repoRootPath,
"repo-root",
"",
"absolute path to the repository root (required if scripts cannot be found via relative paths)",
)
}

var _ = ginkgo.Describe("[Bootstrap Tester]", func() {
Expand Down Expand Up @@ -238,12 +240,17 @@ func buildAvalanchegoImage(tc tests.TestContext, imageName string, forceNewHash
func buildImage(tc tests.TestContext, imageName string, forceNewHash bool, scriptName string) {
require := require.New(tc)

repoRoot, err := e2e.GetRepoRootPath(repoRelativePath)
require.NoError(err)
scriptPath := filepath.Join("..", "..", "..", "..", "scripts", scriptName)
if _, err := os.Stat(scriptPath); err != nil {
if repoRootPath != "" {
scriptPath = filepath.Join(repoRootPath, "scripts", scriptName)
}
require.NoError(err, "failed to locate %s - try specifying -repo-root flag", scriptName)
}

args := []string{
"-x", // Ensure script output to aid in debugging
filepath.Join(repoRoot, "scripts", scriptName),
scriptPath,
}
if forceNewHash {
// Ensure the build results in a new image hash by preventing use of a cached final stage
Expand Down
19 changes: 0 additions & 19 deletions tests/fixture/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,22 +357,3 @@ func NewPChainFeeCalculatorFromContext(context *builder.Context) fee.Calculator
}
return fee.NewSimpleCalculator(0)
}

// GetRepoRootPath strips the provided suffix from the current working
// directory. If the test binary is executed from the root of the repo, the
// result will be the repo root.
func GetRepoRootPath(suffix string) (string, error) {
// - When executed via a test binary, the working directory will be wherever
// the binary is executed from, but scripts should require execution from
// the repo root.
//
// - When executed via ginkgo (nicer for development + supports
// parallel execution) the working directory will always be the
// target path (e.g. [repo root]./tests/bootstrap/e2e) and getting the repo
// root will require stripping the target path suffix.
cwd, err := os.Getwd()
if err != nil {
return "", err
}
return strings.TrimSuffix(cwd, suffix), nil
}
Loading