From 6231652e87097dffcdc0115e470fd478ddae39de Mon Sep 17 00:00:00 2001 From: Emmanuel Odeke Date: Mon, 27 Nov 2017 21:12:00 -0700 Subject: [PATCH] tests: sunset tmlibs/process.Process Updates https://github.com/tendermint/tmlibs/issues/81 No longer using tmlibs/process.Process as we deemed it racy and would incur a maintenance cost yet not used anywhere else but in these tests and not in actual code. --- tests/test_app/app.go | 22 ---------------------- tests/test_app/main.go | 30 ++++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/tests/test_app/app.go b/tests/test_app/app.go index 59d7aec4..f7ecbef5 100644 --- a/tests/test_app/app.go +++ b/tests/test_app/app.go @@ -4,34 +4,12 @@ import ( "bytes" "fmt" "os" - "time" abcicli "github.com/tendermint/abci/client" "github.com/tendermint/abci/types" "github.com/tendermint/tmlibs/log" - "github.com/tendermint/tmlibs/process" ) -func startApp(abciApp string) *process.Process { - // Start the app - //outBuf := NewBufferCloser(nil) - proc, err := process.StartProcess("abci_app", - "", - "bash", - []string{"-c", fmt.Sprintf("abci-cli %s", abciApp)}, - nil, - os.Stdout, - ) - if err != nil { - panicf("running abci_app: %v", err) - } - - // TODO a better way to handle this? - time.Sleep(time.Second) - - return proc -} - func startClient(abciType string) abcicli.Client { // Start client client, err := abcicli.NewClient("tcp://127.0.0.1:46658", abciType, true) diff --git a/tests/test_app/main.go b/tests/test_app/main.go index 376c02fe..e6b11616 100644 --- a/tests/test_app/main.go +++ b/tests/test_app/main.go @@ -2,7 +2,10 @@ package main import ( "fmt" + "log" "os" + "os/exec" + "time" "github.com/tendermint/abci/types" ) @@ -20,6 +23,19 @@ func main() { testCounter() } +func ensureABCIIsUp(subCommand string, n int) error { + var err error + for i := 0; i < n; i++ { + cmd := exec.Command("bash", "-c", "abci-cli", subCommand) + _, err = cmd.CombinedOutput() + if err == nil { + break + } + <-time.After(500 * time.Second) + } + return err +} + func testCounter() { abciApp := os.Getenv("ABCI_APP") if abciApp == "" { @@ -27,8 +43,18 @@ func testCounter() { } fmt.Printf("Running %s test with abci=%s\n", abciApp, abciType) - appProc := startApp(abciApp) - defer appProc.StopProcess(true) + cmd := exec.Command("bash", "-c", fmt.Sprintf("abci-cli %s", abciApp)) + cmd.Stdout = os.Stdout + if err := cmd.Start(); err != nil { + log.Fatalf("starting %q err: %v", abciApp, err) + } + defer cmd.Wait() + defer cmd.Process.Kill() + + if err := ensureABCIIsUp("echo", 5); err != nil { + log.Fatalf("echo failed: %v", err) + } + client := startClient(abciType) defer client.Stop()