Browse Source

tests: fix ensureABCIIsUp

pull/1780/head
Ethan Buchman 7 years ago
parent
commit
9ed5787b6a
3 changed files with 38 additions and 27 deletions
  1. +1
    -0
      tests/test.sh
  2. +13
    -4
      tests/test_app/main.go
  3. +24
    -23
      tests/test_cli/test.sh

+ 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


+ 13
- 4
tests/test_app/main.go View File

@ -23,15 +23,24 @@ func main() {
testCounter()
}
func ensureABCIIsUp(subCommand string, n int) error {
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", "abci-cli", subCommand)
cmd := exec.Command("bash", "-c", cmdString)
_, err = cmd.CombinedOutput()
if err == nil {
break
}
<-time.After(500 * time.Second)
<-time.After(500 * time.Millisecond)
}
return err
}
@ -51,7 +60,7 @@ func testCounter() {
defer cmd.Wait()
defer cmd.Process.Kill()
if err := ensureABCIIsUp("echo", 5); err != nil {
if err := ensureABCIIsUp(abciType, maxABCIConnectTries); err != nil {
log.Fatalf("echo failed: %v", err)
}


+ 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