From c194e96d592f7b6228e62d395e500c114e584d78 Mon Sep 17 00:00:00 2001 From: Michael Glass Date: Mon, 21 Oct 2024 10:54:11 +0200 Subject: [PATCH] cleanup postgres after `run-tests.sh` --- nri-postgresql/cleanup-postgres.sh | 7 +++++++ nri-postgresql/setup-postgres.sh | 3 +-- run-tests.sh | 28 ++++++++++++++-------------- 3 files changed, 22 insertions(+), 16 deletions(-) create mode 100755 nri-postgresql/cleanup-postgres.sh diff --git a/nri-postgresql/cleanup-postgres.sh b/nri-postgresql/cleanup-postgres.sh new file mode 100755 index 00000000..727e8895 --- /dev/null +++ b/nri-postgresql/cleanup-postgres.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +PGDATA="$(realpath ../_build/postgres/data)" +export PGDATA +export PGUSER=$USER +pg_ctl stop || true +rm -rf "$PGDATA" diff --git a/nri-postgresql/setup-postgres.sh b/nri-postgresql/setup-postgres.sh index eb3b1231..da52f04c 100755 --- a/nri-postgresql/setup-postgres.sh +++ b/nri-postgresql/setup-postgres.sh @@ -5,8 +5,7 @@ mkdir -p "../_build/postgres/data" PGDATA="$(realpath ../_build/postgres/data)" export PGDATA export PGUSER=$USER -pg_ctl stop || true -rm -rf "$PGDATA" +source cleanup-postgres.sh initdb --no-locale --encoding=UTF8 pg_ctl start -o '-k . -p 5432' diff --git a/run-tests.sh b/run-tests.sh index 34544b7d..f27073fc 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -10,22 +10,21 @@ popd ## block us, if it happens to be enabled. This is an instance for testing only. mkdir -p ./_build/redis/data redis-server --daemonize yes \ - --dir ./_build/redis/data \ - --save '' \ - --stop-writes-on-bgsave-error no + --dir ./_build/redis/data \ + --save '' \ + --stop-writes-on-bgsave-error no -## start zookeeper (for kafka) +## start zookeeper (for kafka) mkdir -p /tmp/zookeeper /tmp/zookeeper-logs -ZOOPIDFILE=/tmp/zookeeper-logs/pid ZOO_LOG_DIR=/tmp/zookeeper-logs zkServer.sh stop zoo_sample.cfg +ZOOPIDFILE=/tmp/zookeeper-logs/pid ZOO_LOG_DIR=/tmp/zookeeper-logs zkServer.sh stop zoo_sample.cfg rm -rf /tmp/zookeeper/* /tmp/zookeeper-logs/* ZOOPIDFILE=/tmp/zookeeper-logs/pid ZOO_LOG_DIR=/tmp/zookeeper-logs zkServer.sh start zoo_sample.cfg ## wait for zookeeper echo "waiting for zookeeper to start" -until nc -vz localhost 2181 -do - sleep 1 -done +until nc -vz localhost 2181; do + sleep 1 +done echo "zookeeper available" ## start kafka @@ -36,16 +35,17 @@ kafka-server-start.sh -daemon "$server_properties_path" --override num.partition ## wait for kafka echo "waiting for kafka to start" -until nc -vz localhost 9092 -do - sleep 1 +until nc -vz localhost 9092; do + sleep 1 done echo "kafka available" - cabal build --offline all cabal test --offline all # cleanup kafka-server-stop.sh -ZOOPIDFILE=/tmp/zookeeper-logs/pid ZOO_LOG_DIR=/tmp/zookeeper-logs zkServer.sh stop zoo_sample.cfg +ZOOPIDFILE=/tmp/zookeeper-logs/pid ZOO_LOG_DIR=/tmp/zookeeper-logs zkServer.sh stop zoo_sample.cfg +pushd nri-postgresql +source cleanup-postgres.sh +popd