From b7dcc63e3724bfc97b91db3684d2154f5f86c5d8 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Wed, 24 Nov 2021 13:45:16 +0100 Subject: [PATCH] nix: Simplify with_tmp_db --- nix/tools/withTools.nix | 8 +------- test/with_tmp_db | 19 +++---------------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/nix/tools/withTools.nix b/nix/tools/withTools.nix index e64bd5f5b..d04da2c46 100644 --- a/nix/tools/withTools.nix +++ b/nix/tools/withTools.nix @@ -60,15 +60,9 @@ let log "Starting the database cluster..." # Instead of listening on a local port, we will listen on a unix domain socket. - pg_ctl -l "$tmpdir/db.log" start -o "-F -c listen_addresses=\"\" -k $PGHOST" \ + pg_ctl -l "$tmpdir/db.log" -w start -o "-F -c listen_addresses=\"\" -k $PGHOST" \ >> "$setuplog" - log "Waiting for the database cluster to be ready..." - # Waiting is required for older versions of Postgres (< 10). - until pg_isready >> "$setuplog"; do - sleep 0.1 - done - stop () { log "Stopping the database cluster..." pg_ctl stop -m i >> "$setuplog" diff --git a/test/with_tmp_db b/test/with_tmp_db index 241a0dbc8..478d5a19e 100755 --- a/test/with_tmp_db +++ b/test/with_tmp_db @@ -69,23 +69,10 @@ PGTZ=UTC initdb --no-locale --encoding=UTF8 --nosync -U "$PGUSER" --auth=trust \ log "Starting the database cluster..." # Instead of listening on a local port, we will listen on a unix domain socket. -pg_ctl -l "$dblog" start -o "-F -c listen_addresses=\"\" -k $PGHOST" \ +pg_ctl -l "$dblog" -w start -o "-F -c listen_addresses=\"\" -k $PGHOST" \ >> "$setuplog" -log "Waiting for the database cluster to be ready..." -# Waiting is required for older versions of Postgres (< 10). -until pg_isready >> "$setuplog"; do - sleep 0.1 -done - -stopped=0 stop() { - # cleaning up once is enough; otherwise we get some errors - if [ $stopped -eq 1 ]; then - return - fi - stopped=1 - log "Stopping the database cluster..." pg_ctl stop -m i >> "$setuplog" @@ -96,7 +83,7 @@ stop() { fi } -trap stop sigint sigterm exit +trap stop EXIT log "Loading fixtures..." psql -v ON_ERROR_STOP=1 -f test/fixtures/load.sql >> "$setuplog" @@ -106,4 +93,4 @@ log "Done. Running command..." # make sure that the database is shut down and the temporary directory is # deleted when the command is done. This is also why we don't `exec` the # command - our trap would be lost if we did that. -"$@" +("$@")