pgrx icon indicating copy to clipboard operation
pgrx copied to clipboard

The test command should not install the extension if it does not control the Postgres install

Open theory opened this issue 1 year ago • 0 comments

Often the user who owns the SHAREDIR is different from the user who the tests should be run as. Specifically, this causes problems for cargo pgrx test when root owns the Postgres install, as is true for nearly all Postgres packages.

I recognize this is not an issue for a Postgres cluster the pgrx init builds for itself, but it will be for extensions one might want to distribute. For example, right now it would be difficult to build add a pgrx extension to apt.postgreql.org because pgrx test will fail with this error:

   0: failed writing `/repo/work/foo-0.1.0/foo` to `/usr/share/postgresql/16/extension/foo`
   1: Permission denied (os error 13)

This is because /usr/share/postgresql is owned by root.

PGXS avoids this issue by requiring the user to run make install before running make installcheck:

The scripts listed in the REGRESS variable are used for regression testing of your module, which can be invoked by make installcheck after doing make install.

IOW, installcheck does not depend on install; they both have to be run as the appropriate user, generally:

sudo make install
make installcheck DBUSER=postgres

However, pgrx test tries to install the extension even if it's already installed! This will still fail:

cargo pgrx init --pg16=$(which pg_config)
sudo cargo pgrx install --test --pg-config $(which pg_config)
cargo pgrx test pg16

The v0.11.4 release adds tooling to avoid this issue if one knows to do it:

cargo pgrx init --pg16=$(which pg_config)
sudo cargo pgrx install --test --pg-config $(which pg_config)
cargo pgrx test pg16 --runas postgres --pgdata /var/lib/postgresql/pgrx

However pgrx test is still installing the extension even if it's already installed. I get that this make it simpler to to iterative development, but users of PGXS just make a habit of running install to install changes before running installcheck.

At any rate, I suppose the current solution is to wait for all pgrx extensions to upgrade to v0.11.4, or for packages to require that version for packaging. But overall I think that installing an extension as part of the test command crosses too many use cases.

Or at least for pg_test tests; plain old Rust tests of course don't require installation so work fine. Perhaps it'd be useful to have the test command only run Rust tests, and an installcheck command run pg_test tests. 'Course I guess that already exists, as one can run cargo test and then cargo pgrx test as a notional installcheck, but the bit where it installs the extension is still an issue.

theory avatar May 10 '24 21:05 theory