postgresqlTestHook: shutdown on failure

Previously, the user of postgresqlTestHook would have needed to set
failureHook accordingly. However, this was not a clean solution, because
postgresqlStop would also run for configure or build failures, before
the server was even started. This gave odd errors from a failed shutdown
in the log.

Now postgresqlStop is only called when it makes sense - and whenever
postgresqlTestHook is used.
This commit is contained in:
Wolfgang Walther 2025-02-23 12:45:31 +01:00
parent 1cf2d6085b
commit 065fefd975
No known key found for this signature in database
GPG key ID: B39893FA5F65CAE1
4 changed files with 4 additions and 5 deletions

View file

@ -1,5 +1,5 @@
preCheckHooks+=('postgresqlStart')
postCheckHooks+=('postgresqlStop')
preCheckHooks+=(postgresqlStart)
postCheckHooks+=(postgresqlStop)
postgresqlStart() {
@ -69,6 +69,7 @@ EOF
echo 'starting postgresql'
eval "${postgresqlStartCommands:-pg_ctl start}"
failureHooks+=(postgresqlStop)
echo 'setting up postgresql'
eval "$postgresqlTestSetupCommands"
@ -80,4 +81,5 @@ EOF
postgresqlStop() {
echo 'stopping postgresql'
pg_ctl stop
failureHooks=("${failureHooks[@]/postgresqlStop}")
}

View file

@ -45,7 +45,6 @@ postgresqlBuildExtension (finalAttrs: {
SELECT * FROM finish();
ROLLBACK;
'';
failureHook = "postgresqlStop";
checkPhase = ''
runHook preCheck
psql -a -v ON_ERROR_STOP=1 -f $sqlPath

View file

@ -92,7 +92,6 @@ postgresqlBuildExtension (finalAttrs: {
];
postgresqlTestUserOptions = "LOGIN SUPERUSER";
failureHook = "postgresqlStop";
# postgis config directory assumes /include /lib from the same root for json-c library
env.NIX_LDFLAGS = "-L${lib.getLib json_c}/lib";

View file

@ -21,7 +21,6 @@ stdenvNoCC.mkDerivation (
postgresqlTestHook
(postgresql.withPackages (ps: [ finalPackage ] ++ (map (p: ps."${p}") withPackages)))
];
failureHook = "postgresqlStop";
postgresqlTestUserOptions = "LOGIN SUPERUSER";
passAsFile = [ "sql" ];
sql =