Browse Source

Merge pull request #139 from tendermint/sunset-tmlibs-process

tests: sunset tmlibs/process.Process
pull/1780/head
Ethan Buchman 7 years ago
committed by GitHub
parent
commit
5c29adc081
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 80 additions and 58 deletions
  1. +10
    -8
      Makefile
  2. +5
    -0
      client/client.go
  3. +2
    -2
      client/grpc_client.go
  4. +1
    -1
      client/socket_client.go
  5. +1
    -0
      tests/test.sh
  6. +0
    -22
      tests/test_app/app.go
  7. +37
    -2
      tests/test_app/main.go
  8. +24
    -23
      tests/test_cli/test.sh

+ 10
- 8
Makefile View File

@ -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

+ 5
- 0
client/client.go View File

@ -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.


+ 2
- 2
client/grpc_client.go View File

@ -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


+ 1
- 1
client/socket_client.go View File

@ -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


+ 1
- 0
tests/test.sh View File

@ -1,4 +1,5 @@
#! /bin/bash
set -e
# test the counter using a go test script
bash tests/test_app/test.sh


+ 0
- 22
tests/test_app/app.go View File

@ -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)


+ 37
- 2
tests/test_app/main.go View File

@ -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()


+ 24
- 23
tests/test_cli/test.sh View File

@ -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


Loading…
Cancel
Save