On 07/02/2015 11:37 PM, Oskari Saarenmaa wrote:
I'm somewhat interested in both #1 & #2 for other projects, but I wrote
this patch to address #3, i.e. to simplify the test setup we have in
place for pgmemcache
(https://github.com/ohmu/pgmemcache/blob/master/localtests.sh) and other
extensions. I'd like to be able to set up a local PG cluster in /tmp or
some other location and load the extensions I just built in there.

Now that's a laudable goal. It indeed would be nice to be able to do "make check" to test an extension, using pgxs. The way "make check" within the PostgreSQL source tree works is that it performs "make install" to install PostgreSQL a temporary location, and installs the extension to that. We can't use "make install" to create a new PostgreSQL installation in an extension, but perhaps you could have a substitute of that that copies an existing installation to a temporary location. I hacked that pgmemcache localtest.sh script to do just that, see attached. That's usable for pgmemcache as it is, but for a general facility, you'd need to put that logic into pgxs instead, and it should also take care of running initdb and starting and stopping the cluster. But pg_regress can already do those things, so that should be easy.

So, I think that's the direction this should be going. In summary, the goal is to make "make check" to work for extensions, and the way to do that is to teach pgxs to create a temporary installation.

- Heikki

diff --git a/.travis.yml b/.travis.yml
index b30af7e..9197690 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -11,7 +11,7 @@ script:
   - PATH=/usr/lib/postgresql/$PGVER/bin/:$PATH ./localtests.sh
 
 after_failure:
-  - cat regressiondata/regression.diffs
+  - cat regression.diffs
 
 env:
   - PGVER=9.1
diff --git a/localtests.sh b/localtests.sh
index d43e15f..956e300 100755
--- a/localtests.sh
+++ b/localtests.sh
@@ -2,17 +2,55 @@
 
 # Create a clean PostgreSQL cluster for our testing
 
-TESTDIR="$(pwd)/regressiondata"
+TESTDIR="$(pwd)/tmp_check"
 export PGPORT=$((10240 + RANDOM / 2))
-export PGDATA="$TESTDIR/pg"
+export PGDATA="$TESTDIR/data"
 
 rm -rf "$TESTDIR"
+
+# Create a minimal PostgreSQL installation, by copying an existing
+# installation. This is a replacement for doing "make install" in the
+# PostgreSQL source tree, for when you don't have the source tree available.
+#
+# The minimum we need to copy from the existing installation are server 'lib'
+# and 'share' directories, and a few binaries.
+#
+# Note that 'pg_config --libdir' is the path to client-side libraries, i.e.
+# libpq, and we don't want to copy that. (on many distributions, libdir points
+# to just /usr/lib, and we certainly don't want to copy that in whole).
+# Also note that we cannot use symlinks for the binaries, because the binaries
+# look at the absolute path they are run from to find the rest of the files
+# they need.
+
+TMP_INSTALL="$TESTDIR/install"
+
+bindir=`pg_config --bindir`
+pkglibdir=`pg_config --pkglibdir`
+sharedir=`pg_config --sharedir`
+
+mkdir -p "$TMP_INSTALL"
+mkdir -p "$TMP_INSTALL$bindir"
+mkdir -p "$TMP_INSTALL$pkglibdir"
+mkdir -p "$TMP_INSTALL$sharedir"
+
+cp -a $bindir/postgres $TMP_INSTALL$bindir
+cp -a $bindir/initdb $TMP_INSTALL$bindir
+cp -a $bindir/pg_ctl $TMP_INSTALL$bindir
+cp -a $pkglibdir/* $TMP_INSTALL$pkglibdir
+cp -a $sharedir/* $TMP_INSTALL$sharedir
+
+export PATH=$TMP_INSTALL$bindir:$PATH
+
+# Install pgmemcache to the temporary installation
+make install DESTDIR=$TMP_INSTALL
+
+# Set up a temporary cluster
 mkdir -p "$PGDATA"
 
 initdb -E UTF-8 --no-locale
+# XXX: Should use pg_config --config-auth to lock down the cluster
 sed -e "s%^#port =.*%port = $PGPORT%" \
     -e "s%^#\(unix_socket_director[a-z]*\) =.*%\1 = '$PGDATA'%" \
-    -e "s%^#dynamic_library_path = .*%dynamic_library_path = '$(pwd):\$libdir'%" \
     -e "s%^#fsync = .*%fsync = off%" \
     -e "s%^#synchronous_commit = .*%synchronous_commit = off%" \
     -i "$PGDATA/postgresql.conf"
@@ -20,15 +58,5 @@ pg_ctl -l "$PGDATA/log" start
 while [ ! -S "$PGDATA/.s.PGSQL.$PGPORT" ]; do sleep 2; done
 trap "pg_ctl stop -m immediate" EXIT
 
-# It's not possible to override the extension path, so we'll just execute
-# the extension SQL directly after mangling it a bit with sed
-
-cp -a Makefile test.sql sql/ expected/ "$TESTDIR"
-sed -e "s%MODULE_PATHNAME%pgmemcache%" \
-    -e "/CREATE EXTENSION/d" -e "/^--/d" -e "/^$/d" \
-    "ext/pgmemcache.sql" > "$TESTDIR/sql/init.sql"
-cp "$TESTDIR/sql/init.sql" "$TESTDIR/expected/init.out"
-
-# Run the actual tests
-
-make -C "$TESTDIR" installcheck REGRESS_OPTS="--host=$PGDATA --port=$PGPORT"
+# Run the actual tests in the temporary cluster.
+make installcheck REGRESS_OPTS="--host=$PGDATA --port=$PGPORT"
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to