diff --git a/Makefile b/Makefile index 11a75664a..cdee195d7 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,8 @@ dist: test: @ find . -path ./vendor -prune -o -name "*.sock" -exec rm {} \; + @ echo "==> Running linter" + @ make metalinter_test @ echo "==> Running go test" @ go test $(PACKAGES) @@ -54,20 +56,20 @@ fmt: get_deps: @ go get -d $(PACKAGES) -tools: +ensure_tools: go get -u -v $(GOTOOLS) + @gometalinter --install -get_vendor_deps: - @ go get github.com/Masterminds/glide +get_vendor_deps: ensure_tools + @rm -rf vendor/ + @echo "--> Running glide install" @ glide install -metalinter: tools - @gometalinter --install +metalinter: protoc --lint_out=. types/*.proto gometalinter --vendor --deadline=600s --enable-all --disable=lll ./... -metalinter_test: tools - @gometalinter --install +metalinter_test: # protoc --lint_out=. types/*.proto gometalinter --vendor --deadline=600s --disable-all \ --enable=maligned \ @@ -103,4 +105,4 @@ build-docker: run-docker: docker run -it --rm -v "$PWD:/go/src/github.com/tendermint/abci" -w "/go/src/github.com/tendermint/abci" "tendermint/abci-dev" /bin/bash -.PHONY: all build test fmt get_deps tools protoc install_protoc build-docker run-docker +.PHONY: all build test fmt get_deps ensure_tools protoc install_protoc build-docker run-docker diff --git a/client/client.go b/client/client.go index ddb589a40..ad0e5a7ab 100644 --- a/client/client.go +++ b/client/client.go @@ -8,6 +8,11 @@ import ( cmn "github.com/tendermint/tmlibs/common" ) +const ( + dialRetryIntervalSeconds = 3 + echoRetryIntervalSeconds = 1 +) + // Client defines an interface for an ABCI client. // All `Async` methods return a `ReqRes` object. // All `Sync` methods return the appropriate protobuf ResponseXxx struct and an error. diff --git a/client/grpc_client.go b/client/grpc_client.go index 6079c90ce..f65d27e69 100644 --- a/client/grpc_client.go +++ b/client/grpc_client.go @@ -56,7 +56,7 @@ RETRY_LOOP: return err } cli.Logger.Error(fmt.Sprintf("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr)) - time.Sleep(time.Second * 3) + time.Sleep(time.Second * dialRetryIntervalSeconds) continue RETRY_LOOP } @@ -68,7 +68,7 @@ RETRY_LOOP: if err == nil { break ENSURE_CONNECTED } - time.Sleep(time.Second) + time.Sleep(time.Second * echoRetryIntervalSeconds) } cli.client = client diff --git a/client/socket_client.go b/client/socket_client.go index 7e5a1f30f..a5d90dbe7 100644 --- a/client/socket_client.go +++ b/client/socket_client.go @@ -68,7 +68,7 @@ RETRY_LOOP: return err } cli.Logger.Error(fmt.Sprintf("abci.socketClient failed to connect to %v. Retrying...", cli.addr)) - time.Sleep(time.Second * 3) + time.Sleep(time.Second * dialRetryIntervalSeconds) continue RETRY_LOOP } cli.conn = conn diff --git a/tests/test.sh b/tests/test.sh index 4087cdceb..c005c0de3 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,4 +1,5 @@ #! /bin/bash +set -e # test the counter using a go test script bash tests/test_app/test.sh diff --git a/tests/test_app/app.go b/tests/test_app/app.go index 59d7aec4b..f7ecbef5e 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 376c02fe5..a21918f51 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,28 @@ func main() { testCounter() } +const ( + maxABCIConnectTries = 10 +) + +func ensureABCIIsUp(typ string, n int) error { + var err error + cmdString := "abci-cli echo hello" + if typ == "grpc" { + cmdString = "abci-cli --abci grpc echo hello" + } + + for i := 0; i < n; i++ { + cmd := exec.Command("bash", "-c", cmdString) // nolint: gas + _, err = cmd.CombinedOutput() + if err == nil { + break + } + <-time.After(500 * time.Millisecond) + } + return err +} + func testCounter() { abciApp := os.Getenv("ABCI_APP") if abciApp == "" { @@ -27,8 +52,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)) // nolint: gas + 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(abciType, maxABCIConnectTries); err != nil { + log.Fatalf("echo failed: %v", err) + } + client := startClient(abciType) defer client.Stop() diff --git a/tests/test_cli/test.sh b/tests/test_cli/test.sh index ea4ea4fa9..f6259148d 100644 --- a/tests/test_cli/test.sh +++ b/tests/test_cli/test.sh @@ -1,4 +1,5 @@ #! /bin/bash +set -e # Get the root directory. SOURCE="${BASH_SOURCE[0]}" @@ -9,29 +10,29 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/../.." && pwd )" cd "$DIR" || exit function testExample() { - N=$1 - INPUT=$2 - APP="$3 $4" - - echo "Example $N: $APP" - $APP &> /dev/null & - sleep 2 - abci-cli --verbose batch < "$INPUT" > "${INPUT}.out.new" - killall "$3" - - pre=$(shasum < "${INPUT}.out") - post=$(shasum < "${INPUT}.out.new") - - if [[ "$pre" != "$post" ]]; then - echo "You broke the tutorial" - echo "Got:" - cat "${INPUT}.out.new" - echo "Expected:" - cat "${INPUT}.out" - exit 1 - fi - - rm "${INPUT}".out.new + N=$1 + INPUT=$2 + APP="$3 $4" + + echo "Example $N: $APP" + $APP &> /dev/null & + sleep 2 + abci-cli --verbose batch < "$INPUT" > "${INPUT}.out.new" + killall "$3" + + pre=$(shasum < "${INPUT}.out") + post=$(shasum < "${INPUT}.out.new") + + if [[ "$pre" != "$post" ]]; then + echo "You broke the tutorial" + echo "Got:" + cat "${INPUT}.out.new" + echo "Expected:" + cat "${INPUT}.out" + exit 1 + fi + + rm "${INPUT}".out.new } testExample 1 tests/test_cli/ex1.abci abci-cli dummy