From c64e73ed0b198e2498eb5c756ae09dbcc52e5e89 Mon Sep 17 00:00:00 2001 From: ptrus Date: Tue, 28 Apr 2020 15:22:34 +0200 Subject: [PATCH] go/oasis-test-runner: add 'late-start' E2E test --- .../scenario/e2e/late_start.go | 84 +++++++++++++++++++ go/oasis-test-runner/test-runner.go | 2 + 2 files changed, 86 insertions(+) create mode 100644 go/oasis-test-runner/scenario/e2e/late_start.go diff --git a/go/oasis-test-runner/scenario/e2e/late_start.go b/go/oasis-test-runner/scenario/e2e/late_start.go new file mode 100644 index 00000000000..68afe41284b --- /dev/null +++ b/go/oasis-test-runner/scenario/e2e/late_start.go @@ -0,0 +1,84 @@ +package e2e + +import ( + "time" + + "github.com/oasislabs/oasis-core/go/oasis-test-runner/env" + "github.com/oasislabs/oasis-core/go/oasis-test-runner/oasis" + "github.com/oasislabs/oasis-core/go/oasis-test-runner/scenario" +) + +var ( + // LateStart is the LateStart node basic scenario. + LateStart scenario.Scenario = newLateStartImpl("late-start", "simple-keyvalue-client", nil) +) + +const lateStartInitialWait = 2 * time.Minute + +type lateStartImpl struct { + basicImpl +} + +func newLateStartImpl(name, clientBinary string, clientArgs []string) scenario.Scenario { + return &lateStartImpl{ + basicImpl: *newBasicImpl(name, clientBinary, clientArgs), + } +} + +func (s *lateStartImpl) Fixture() (*oasis.NetworkFixture, error) { + f, err := s.basicImpl.Fixture() + if err != nil { + return nil, err + } + + // Start without a client. + f.Clients = []oasis.ClientFixture{} + + return f, nil +} + +func (s *lateStartImpl) Run(childEnv *env.Env) error { + // Start the network. + var err error + if err = s.net.Start(); err != nil { + return err + } + + s.logger.Info("Waiting before starting the client node", + "wait_for", lateStartInitialWait, + ) + time.Sleep(lateStartInitialWait) + + s.logger.Info("Starting the client node") + clientFixture := &oasis.ClientFixture{} + client, err := clientFixture.Create(s.net) + if err != nil { + return err + } + if err = client.Start(); err != nil { + return err + } + + s.logger.Info("Starting the basic client") + // Start basic client. + cmd, err := startClient(childEnv, s.net, resolveClientBinary(s.clientBinary), s.clientArgs) + if err != nil { + return err + } + clientErrCh := make(chan error) + go func() { + clientErrCh <- cmd.Wait() + }() + + // Wait for the client to exit. + select { + case err = <-clientErrCh: + _ = cmd.Process.Kill() + case err = <-clientErrCh: + } + if err != nil { + return err + } + + return nil +} diff --git a/go/oasis-test-runner/test-runner.go b/go/oasis-test-runner/test-runner.go index 35f81c039c6..50ae664026f 100644 --- a/go/oasis-test-runner/test-runner.go +++ b/go/oasis-test-runner/test-runner.go @@ -67,6 +67,8 @@ func main() { _ = cmd.Register(e2e.NodeUpgradeCancel) // Debonding entries from genesis test. _ = cmd.Register(e2e.Debond) + // Late start test. + _ = cmd.Register(e2e.LateStart) // Register the remote signer test cases. rootCmd.Flags().AddFlagSet(remotesigner.Flags)