Skip to content

Commit

Permalink
use anr pid in e2e test yaml (ava-labs#292)
Browse files Browse the repository at this point in the history
* use anr pid in e2e test yaml

* fix parser

* fix naming in simulator to not be confused as ANR output

* rename to SaveClusterInfo

Co-authored-by: aaronbuchwald <aaron.buchwald56@gmail.com>
  • Loading branch information
2 people authored and arunraoshrap committed Nov 8, 2022
1 parent 72ac8ea commit 88db21d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
18 changes: 9 additions & 9 deletions cmd/simulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
timeout time.Duration
keysDir string

networkRunnerOutputPath string
clusterInfoYamlPath string
rpcEndpoints []string

concurrency int
Expand All @@ -52,7 +52,7 @@ func newCommand() *cobra.Command {

cmd.PersistentFlags().DurationVarP(&timeout, "timeout", "t", time.Minute, "Duration to run simulator")
cmd.PersistentFlags().StringVarP(&keysDir, "keys", "k", ".simulator/keys", "Directory for key files")
cmd.PersistentFlags().StringVarP(&networkRunnerOutputPath, "network-runner-output", "o", "", "If non-empty, it loads the endpoints from the YAML and overwrites --config")
cmd.PersistentFlags().StringVarP(&clusterInfoYamlPath, "cluster-info-yaml", "o", "", "If non-empty, it loads the endpoints from the YAML and overwrites --config")
cmd.PersistentFlags().StringSliceVarP(&rpcEndpoints, "endpoints", "e", nil, "If non-empty, it loads the endpoints from the YAML and overwrites --config")
cmd.PersistentFlags().IntVarP(&concurrency, "concurrency", "c", 10, "Concurrency")
cmd.PersistentFlags().Uint64VarP(&baseFee, "base-fee", "f", 25, "Base fee")
Expand All @@ -62,8 +62,8 @@ func newCommand() *cobra.Command {
}

func runFunc(cmd *cobra.Command, args []string) {
log.Printf("launching simulator with rpc endpoints %q or network runner output %q, timeout %v, concurrentcy %d, base fee %d, priority fee %d",
rpcEndpoints, networkRunnerOutputPath, timeout, concurrency, baseFee, priorityFee)
log.Printf("launching simulator with rpc endpoints %q or cluster info yaml %q, timeout %v, concurrentcy %d, base fee %d, priority fee %d",
rpcEndpoints, clusterInfoYamlPath, timeout, concurrency, baseFee, priorityFee)

cfg := &worker.Config{
Endpoints: rpcEndpoints,
Expand All @@ -72,15 +72,15 @@ func runFunc(cmd *cobra.Command, args []string) {
PriorityFee: priorityFee,
}

if networkRunnerOutputPath != "" {
log.Printf("loading network runner output %q", networkRunnerOutputPath)
b, err := os.ReadFile(networkRunnerOutputPath)
if clusterInfoYamlPath != "" {
log.Printf("loading cluster info yaml %q", clusterInfoYamlPath)
b, err := os.ReadFile(clusterInfoYamlPath)
if err != nil {
log.Fatalf("failed to read network-runner output %v", err)
log.Fatalf("failed to read cluster info yaml %v", err)
}
var ci networkRunnerClusterInfo
if err = yaml.Unmarshal(b, &ci); err != nil {
log.Fatalf("failed to parse network-runner output %v", err)
log.Fatalf("failed to parse cluster info yaml %v", err)
}

eps := make([]string, len(ci.URIs))
Expand Down
4 changes: 2 additions & 2 deletions scripts/parser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func startSubnet(outputFile string, avalanchegoPath string, pluginDir string, gr
if err != nil {
panic(err)
}
blockchainId, logsDir, err := runner.WaitForCustomVm(vmId)
blockchainId, logsDir, pid, err := runner.WaitForCustomVm(vmId)
if err != nil {
panic(err)
}
runner.GetClusterInfo(blockchainId, logsDir)
runner.SaveClusterInfo(blockchainId, logsDir, pid)
}

func parseMetamask(outputFile string, chainId string, address string) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ run_simulator() {

echo "running simulator"
simulator \
--network-runner-output=$BASEDIR/avalanchego-${VERSION}/output.yaml \
--cluster-info-yaml=$BASEDIR/avalanchego-${VERSION}/output.yaml \
--keys=./cmd/simulator/.simulator/keys \
--timeout=30s \
--concurrency=10 \
Expand Down
5 changes: 4 additions & 1 deletion tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ var _ = ginkgo.BeforeSuite(func() {

subnetEVMRPCEps = make([]string, 0)
blockchainID, logsDir := "", ""
pid := 0

// wait up to 5-minute for custom VM installation
outf("\n{{magenta}}waiting for all custom VMs to report healthy...{{/}}\n")
Expand All @@ -196,6 +197,9 @@ done:
// all logs are stored under root data dir
logsDir = resp.GetClusterInfo().GetRootDataDir()

// ANR server pid
pid = int(resp.GetClusterInfo().GetPid())

for blkChainID, vmInfo := range resp.ClusterInfo.CustomChains {
if vmInfo.VmId == vmID.String() {
blockchainID = blkChainID
Expand All @@ -222,7 +226,6 @@ done:
outf("{{blue}}avalanche subnet-evm RPC:{{/}} %q\n", rpcEP)
}

pid := os.Getpid()
outf("{{blue}}{{bold}}writing output %q with PID %d{{/}}\n", utils.GetOutputPath(), pid)
ci := clusterInfo{
URIs: uris,
Expand Down
26 changes: 16 additions & 10 deletions tests/e2e/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ func startRunner(vmName string, genesisPath string, pluginDir string) error {
return nil
}

func WaitForCustomVm(vmId ids.ID) (string, string, error) {
func WaitForCustomVm(vmId ids.ID) (string, string, int, error) {
blockchainID, logsDir := "", ""
pid := 0

// wait up to 5-minute for custom VM installation
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
Expand All @@ -111,7 +112,7 @@ done:
ccancel()
if err != nil {
cancel()
return "", "", err
return "", "", 0, err
}

if !resp.ClusterInfo.Healthy {
Expand All @@ -125,6 +126,9 @@ done:
// all logs are stored under root data dir
logsDir = resp.GetClusterInfo().GetRootDataDir()

// ANR server pid
pid = int(resp.GetClusterInfo().GetPid())

for chainID, chainInfo := range resp.ClusterInfo.CustomChains {
if chainInfo.VmId == vmId.String() {
blockchainID = chainID
Expand All @@ -136,20 +140,23 @@ done:
err := ctx.Err()
if err != nil {
cancel()
return "", "", err
return "", "", 0, err
}
cancel()

if blockchainID == "" {
return "", "", errors.New("BlockchainId not found")
return "", "", 0, errors.New("BlockchainId not found")
}
if logsDir == "" {
return "", "", errors.New("logsDir not found")
return "", "", 0, errors.New("logsDir not found")
}
if pid == 0 {
return "", "", pid, errors.New("pid not found")
}
return blockchainID, logsDir, nil
return blockchainID, logsDir, pid, nil
}

func GetClusterInfo(blockchainId string, logsDir string) (clusterInfo, error) {
func SaveClusterInfo(blockchainId string, logsDir string, pid int) (clusterInfo, error) {
cctx, ccancel := context.WithTimeout(context.Background(), 2*time.Minute)
uris, err := cli.URIs(cctx)
ccancel()
Expand All @@ -165,7 +172,6 @@ func GetClusterInfo(blockchainId string, logsDir string) (clusterInfo, error) {
outf("{{blue}}avalanche subnet-evm RPC:{{/}} %q\n", rpcEP)
}

pid := os.Getpid()
ci := clusterInfo{
URIs: uris,
Endpoint: fmt.Sprintf("/ext/bc/%s", blockchainId),
Expand All @@ -183,13 +189,13 @@ func StartNetwork(vmId ids.ID, vmName string, genesisPath string, pluginDir stri
fmt.Println("Starting network")
startRunner(vmName, genesisPath, pluginDir)

blockchainId, logsDir, err := WaitForCustomVm(vmId)
blockchainId, logsDir, pid, err := WaitForCustomVm(vmId)
if err != nil {
return clusterInfo{}, err
}
fmt.Println("Got custom vm")

return GetClusterInfo(blockchainId, logsDir)
return SaveClusterInfo(blockchainId, logsDir, pid)
}

func StopNetwork() error {
Expand Down

0 comments on commit 88db21d

Please sign in to comment.