mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-03 06:37:14 +00:00
Merge pull request #139 from tendermint/sunset-tmlibs-process
tests: sunset tmlibs/process.Process
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,4 +1,5 @@
|
||||
#! /bin/bash
|
||||
set -e
|
||||
|
||||
# test the counter using a go test script
|
||||
bash tests/test_app/test.sh
|
||||
|
||||
@@ -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
@@ -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()
|
||||
|
||||
|
||||
+20
-19
@@ -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"
|
||||
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"
|
||||
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")
|
||||
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
|
||||
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
|
||||
rm "${INPUT}".out.new
|
||||
}
|
||||
|
||||
testExample 1 tests/test_cli/ex1.abci abci-cli dummy
|
||||
|
||||
Reference in New Issue
Block a user