From fcb7466f35f06f76f0e59ba25acededca711af37 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Wed, 24 May 2017 16:32:56 +0200 Subject: [PATCH] tests: hold off until daemon is available The postgresql container initializes DB files e.a. in these tests, this can take a couple of seconds. Try contacting it for up to 20 seconds, and only then run the tests: create a table, store something in it and retrieve it again. --- tests/config.yaml | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/config.yaml b/tests/config.yaml index 1cbd39a..556a512 100644 --- a/tests/config.yaml +++ b/tests/config.yaml @@ -43,11 +43,23 @@ test: done test "$up" -ne 0 testhost: - selfcheck: - - 'env PGPASSWORD=mtftest psql -h localhost -U mtftest -f test.sql | egrep "anything|something"' - #- 'echo errr | nc localhost 11211' - #- 'echo set AAA 0 4 2 | nc localhost 11211' - #- 'echo get AAA | nc localhost 11211' - #selcheckError: - #- 'echo errr | nc localhost 11211 |grep ERROR' - + db_usable: + - | + export PGPASSWORD=mtftest + PSQL="psql -h localhost -U mtftest -q" + up=0 + for i in `seq 20`; do + echo "Pinging PostgreSQL ($i)" + if $PSQL -c "" >&/dev/null; then + up=1 + break + else + sleep 1 + fi + done + if [ "$up" -eq 1 ]; then + $PSQL -f test.sql | egrep "anything|something" + else + echo "Unable to connect to database." >&2 + false + fi