Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgresqlTestHook: run postgresqlTestSetupPost hook after setting up #212555

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/hooks/postgresql-test-hook.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Bash-only variables:
- `postgresqlEnableTCP`: set to `1` to enable TCP listening. Flaky; not recommended.
- `postgresqlStartCommands`: defaults to `pg_ctl start`.

## Hooks {#sec-postgresqlTestHook-hooks}

A number of additional hooks are ran in postgresqlTestHook

- `postgresqlTestSetupPost`: ran after postgresql has been set up.

## TCP and the Nix sandbox {#sec-postgresqlTestHook-tcp}

`postgresqlEnableTCP` relies on network sandboxing, which is not available on macOS and some custom Nix installations, resulting in flaky tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ EOF
header 'setting up postgresql'
eval "$postgresqlTestSetupCommands"

runHook postgresqlTestSetupPost

}

postgresqlStop() {
Expand Down
5 changes: 4 additions & 1 deletion pkgs/build-support/setup-hooks/postgresql-test-hook/test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ stdenv.mkDerivation {
INSERT INTO hello VALUES ('it '||'worked');
SELECT * FROM hello;
'';
postgresqlTestSetupPost = ''
TEST_POST_HOOK_RAN=1
'';
checkPhase = ''
runHook preCheck
psql <$sqlPath | grep 'it worked'
TEST_RAN=1
runHook postCheck
'';
installPhase = ''
[[ $TEST_RAN == 1 ]]
[[ $TEST_RAN == 1 && $TEST_POST_HOOK_RAN == 1 ]]
touch $out
'';
}