Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu committed May 17, 2022
1 parent d5e9c19 commit 98f6755
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 60 deletions.
4 changes: 3 additions & 1 deletion scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ PID=${!}
echo "running e2e tests"
./tests/e2e/e2e.test \
--ginkgo.v \
--log-level debug || EXIT_CODE=$?
--log-level debug \
--network-runner-avalanchego-path=${AVALANCHEGO_PATH} \
--network-runner-avalanchego-log-level=${AVALANCHE_LOG_LEVEL} || EXIT_CODE=$?

# "e2e.test" already terminates the cluster
# just in case tests are aborted, manually terminate them again
Expand Down
94 changes: 35 additions & 59 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package e2e_test
import (
"context"
"flag"
"os"
"strings"
"testing"
"time"

Expand All @@ -17,6 +15,9 @@ import (

ginkgo "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"

// ensure test packages are scanned by ginkgo
_ "github.com/ava-labs/avalanche-rosetta/tests/e2e/transfer"
)

func TestE2E(t *testing.T) {
Expand All @@ -34,22 +35,13 @@ var (
uris string
)

// TODO: support existing keys

func init() {
flag.StringVar(
&logLevel,
"log-level",
"info",
"log level",
)

flag.StringVar(
&networkRunnerGRPCEp,
"network-runner-grpc-endpoint",
"",
"[optional] gRPC server endpoint for network-runner (only required for local network-runner tests)",
)
flag.StringVar(
&networkRunnerAvalancheGoExecPath,
"network-runner-avalanchego-path",
Expand All @@ -65,58 +57,42 @@ func init() {
}

var _ = ginkgo.BeforeSuite(func() {
if networkRunnerAvalancheGoExecPath != "" {
_, err := os.Stat(networkRunnerAvalancheGoExecPath)
gomega.Expect(err).Should(gomega.BeNil())
}

// run with local network-runner
if networkRunnerGRPCEp != "" {
gomega.Expect(uris).Should(gomega.BeEmpty())

runnerCli, err := e2e.SetRunnerClient(logLevel, networkRunnerGRPCEp)
gomega.Expect(err).Should(gomega.BeNil())

ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
presp, err := runnerCli.Ping(ctx)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
tests.Outf("{{green}}network-runner running in PID %d{{/}}\n", presp.Pid)

tests.Outf("{{magenta}}starting network-runner with %q{{/}}\n", networkRunnerAvalancheGoExecPath)
ctx, cancel = context.WithTimeout(context.Background(), 15*time.Second)
resp, err := runnerCli.Start(ctx, networkRunnerAvalancheGoExecPath,
runner_sdk.WithNumNodes(5),
runner_sdk.WithLogLevel(networkRunnerAvalancheGoLogLevel),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
tests.Outf("{{green}}successfully started network-runner :{{/}} %+v\n", resp.ClusterInfo.NodeNames)

// start is async, so wait some time for cluster health
time.Sleep(time.Minute)
gomega.Expect(uris).Should(gomega.BeEmpty())

runnerCli, err := e2e.SetRunnerClient(logLevel, networkRunnerGRPCEp)
gomega.Expect(err).Should(gomega.BeNil())

ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
presp, err := runnerCli.Ping(ctx)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
tests.Outf("{{green}}network-runner running in PID %d{{/}}\n", presp.Pid)

tests.Outf("{{magenta}}starting network-runner with %q{{/}}\n", networkRunnerAvalancheGoExecPath)
ctx, cancel = context.WithTimeout(context.Background(), 15*time.Second)
resp, err := runnerCli.Start(ctx, networkRunnerAvalancheGoExecPath,
runner_sdk.WithNumNodes(5),
runner_sdk.WithLogLevel(networkRunnerAvalancheGoLogLevel),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
tests.Outf("{{green}}successfully started network-runner :{{/}} %+v\n", resp.ClusterInfo.NodeNames)

ctx, cancel = context.WithTimeout(context.Background(), 2*time.Minute)
_, err = runnerCli.Health(ctx)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
// start is async, so wait some time for cluster health
time.Sleep(time.Minute)

var uriSlice []string
ctx, cancel = context.WithTimeout(context.Background(), 2*time.Minute)
uriSlice, err = runnerCli.URIs(ctx)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
e2e.SetURIs(uriSlice)
}
ctx, cancel = context.WithTimeout(context.Background(), 2*time.Minute)
_, err = runnerCli.Health(ctx)
cancel()
gomega.Expect(err).Should(gomega.BeNil())

// connect directly to existing cluster
if uris != "" {
gomega.Expect(networkRunnerGRPCEp).Should(gomega.BeEmpty())
var uriSlice []string
ctx, cancel = context.WithTimeout(context.Background(), 2*time.Minute)
uriSlice, err = runnerCli.URIs(ctx)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
e2e.SetURIs(uriSlice)

uriSlice := strings.Split(uris, ",")
e2e.SetURIs(uriSlice)
}
uriSlice := e2e.GetURIs()
tests.Outf("{{green}}URIs:{{/}} %q\n", uriSlice)
})

Expand Down

0 comments on commit 98f6755

Please sign in to comment.