mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 08:56:34 +03:00
Run the test suite with postgres versions not available on travis
This commit is contained in:
parent
9f467231d9
commit
f5cad47909
|
@ -1,60 +1,131 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e -x
|
||||||
|
|
||||||
# Prepare the test databases in Travis CI.
|
# Prepare the test databases in Travis CI.
|
||||||
|
#
|
||||||
# The script should be run with sudo.
|
# The script should be run with sudo.
|
||||||
# The script is not idempotent: it assumes the machine in a clean state
|
# The script is not idempotent: it assumes the machine in a clean state
|
||||||
# and is designed for a sudo-enabled Trusty environment.
|
# and is designed for a sudo-enabled Trusty environment.
|
||||||
|
#
|
||||||
|
# The variables TEST_PAST, TEST_FUTURE, DONT_TEST_PRESENT can be used to test
|
||||||
|
# against unsupported Postgres versions and skip tests with supported ones.
|
||||||
|
#
|
||||||
|
# The variables can be set in the travis configuration
|
||||||
|
# (https://travis-ci.org/psycopg/psycopg2/settings)
|
||||||
|
|
||||||
set_param () {
|
set_param () {
|
||||||
# Set a parameter in a postgresql.conf file
|
# Set a parameter in a postgresql.conf file
|
||||||
version=$1
|
param=$1
|
||||||
param=$2
|
value=$2
|
||||||
value=$3
|
|
||||||
|
|
||||||
sed -i "s/^\s*#\?\s*$param.*/$param = $value/" \
|
sed -i "s/^\s*#\?\s*$param.*/$param = $value/" "$DATADIR/postgresql.conf"
|
||||||
"/etc/postgresql/$version/psycopg/postgresql.conf"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
create () {
|
create () {
|
||||||
version=$1
|
export VERSION=$1
|
||||||
port=$2
|
export PACKAGE=${2:-$VERSION}
|
||||||
dbname=psycopg2_test
|
|
||||||
|
|
||||||
pg_createcluster -p $port --start-conf manual $version psycopg
|
# Version as number: 9.6 -> 906
|
||||||
|
export VERNUM=$(( $(echo $VERSION \
|
||||||
|
| sed 's/\(.\+\)\.\(.\+\)/100 * \1 + \2/') ))
|
||||||
|
|
||||||
# for two-phase commit testing
|
# Port number: 9.6 -> 50906
|
||||||
set_param "$version" max_prepared_transactions 10
|
export PORT=$(( 50000 + $VERNUM ))
|
||||||
|
|
||||||
# for replication testing
|
export DATADIR="/var/lib/postgresql/$PACKAGE/psycopg"
|
||||||
set_param "$version" max_wal_senders 5
|
export PGDIR="/usr/lib/postgresql/$PACKAGE"
|
||||||
set_param "$version" max_replication_slots 5
|
export PGBIN="$PGDIR/bin"
|
||||||
if [ "$version" == "9.2" -o "$version" == "9.3" ]
|
|
||||||
then
|
# install postgres versions not available on the image
|
||||||
set_param "$version" wal_level hot_standby
|
if (( "$VERNUM" < 902 || "$VERNUM" > 906 )); then
|
||||||
else
|
wget -O - http://initd.org/psycopg/tarballs/postgresql/postgresql-${PACKAGE}.tar.bz2 \
|
||||||
set_param "$version" wal_level logical
|
| sudo tar xjf - -C /usr/lib/postgresql
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "local replication travis trust" \
|
sudo -u postgres "$PGBIN/initdb" -D "$DATADIR"
|
||||||
>> "/etc/postgresql/$version/psycopg/pg_hba.conf"
|
|
||||||
|
|
||||||
|
set_param port "$PORT"
|
||||||
|
if (( "$VERNUM" >= 800 )); then
|
||||||
|
set_param listen_addresses "'*'"
|
||||||
|
else
|
||||||
|
set_param tcpip_socket true
|
||||||
|
fi
|
||||||
|
|
||||||
pg_ctlcluster "$version" psycopg start
|
# for two-phase commit testing
|
||||||
|
if (( "$VERNUM" >= 801 )); then set_param max_prepared_transactions 10; fi
|
||||||
|
|
||||||
sudo -u postgres psql -c "create user travis replication" "port=$port"
|
# for replication testing
|
||||||
sudo -u postgres psql -c "create database $dbname" "port=$port"
|
if (( "$VERNUM" >= 900 )); then set_param max_wal_senders 5; fi
|
||||||
sudo -u postgres psql -c "grant create on database $dbname to travis" "port=$port"
|
if (( "$VERNUM" >= 904 )); then set_param max_replication_slots 5; fi
|
||||||
sudo -u postgres psql -c "create extension hstore" "port=$port dbname=$dbname"
|
|
||||||
|
if (( "$VERNUM" >= 904 )); then
|
||||||
|
set_param wal_level logical
|
||||||
|
elif (( "$VERNUM" >= 900 )); then
|
||||||
|
set_param wal_level hot_standby
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( "$VERNUM" >= 900 )); then
|
||||||
|
echo "host replication travis 0.0.0.0/0 trust" >> "$DATADIR/pg_hba.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# start the server, wait for start
|
||||||
|
sudo -u postgres "$PGBIN/pg_ctl" -w -l /dev/null -D "$DATADIR" start
|
||||||
|
|
||||||
|
# create the test database
|
||||||
|
DBNAME=psycopg2_test
|
||||||
|
CONNINFO="user=postgres host=localhost port=$PORT dbname=template1"
|
||||||
|
|
||||||
|
if (( "$VERNUM" >= 901 )); then
|
||||||
|
psql -c "create user travis createdb createrole replication" "$CONNINFO"
|
||||||
|
elif (( "$VERNUM" >= 801 )); then
|
||||||
|
psql -c "create user travis createdb createrole" "$CONNINFO"
|
||||||
|
else
|
||||||
|
psql -c "create user travis createdb createuser" "$CONNINFO"
|
||||||
|
fi
|
||||||
|
|
||||||
|
psql -c "create database $DBNAME with owner travis" "$CONNINFO"
|
||||||
|
|
||||||
|
# configure global objects on the test database
|
||||||
|
CONNINFO="user=postgres host=localhost port=$PORT dbname=$DBNAME"
|
||||||
|
|
||||||
|
if (( "$VERNUM" >= 901 )); then
|
||||||
|
psql -c "create extension hstore" "$CONNINFO"
|
||||||
|
elif (( "$VERNUM" >= 803 )); then
|
||||||
|
psql -f "$PGDIR/share/contrib/hstore.sql" "$CONNINFO"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( "$VERNUM" == 901 )); then
|
||||||
|
psql -c "create extension json" "$CONNINFO"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Would give a permission denied error in the travis build dir
|
# Would give a permission denied error in the travis build dir
|
||||||
cd /
|
cd /
|
||||||
|
|
||||||
create 9.6 54396
|
# Postgres versions supported by Travis CI
|
||||||
create 9.5 54395
|
if [[ -z "$DONT_TEST_PRESENT" ]]; then
|
||||||
create 9.4 54394
|
create 9.6
|
||||||
create 9.3 54393
|
create 9.5
|
||||||
create 9.2 54392
|
create 9.4
|
||||||
|
create 9.3
|
||||||
|
create 9.2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Unsupported postgres versions that we still support
|
||||||
|
# Images built by https://github.com/psycopg/psycopg2-wheels/tree/build-dinosaurs
|
||||||
|
if [[ -n "$TEST_PAST" ]]; then
|
||||||
|
create 7.4
|
||||||
|
create 8.0
|
||||||
|
create 8.1
|
||||||
|
create 8.2
|
||||||
|
create 8.3
|
||||||
|
create 8.4
|
||||||
|
create 9.0
|
||||||
|
create 9.1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Postgres built from master
|
||||||
|
if [[ -n "$TEST_FUTURE" ]]; then
|
||||||
|
create 10.0 10-master
|
||||||
|
fi
|
||||||
|
|
|
@ -2,29 +2,71 @@
|
||||||
|
|
||||||
# Run the tests in all the databases
|
# Run the tests in all the databases
|
||||||
# The script is designed for a Trusty environment.
|
# The script is designed for a Trusty environment.
|
||||||
|
#
|
||||||
|
# The variables TEST_PAST, TEST_FUTURE, DONT_TEST_PRESENT can be used to test
|
||||||
|
# against unsupported Postgres versions and skip tests with supported ones.
|
||||||
|
#
|
||||||
|
# The variables TEST_VERBOSE enables verbose test log.
|
||||||
|
#
|
||||||
|
# The variables can be set in the travis configuration
|
||||||
|
# (https://travis-ci.org/psycopg/psycopg2/settings)
|
||||||
|
|
||||||
set -e
|
set -e -x
|
||||||
|
|
||||||
run_test () {
|
run_test () {
|
||||||
version=$1
|
VERSION=$1
|
||||||
port=$2
|
DBNAME=psycopg2_test
|
||||||
dbname=psycopg2_test
|
if [[ -n "$TEST_VERBOSE" ]]; then
|
||||||
|
VERBOSE=--verbose
|
||||||
|
else
|
||||||
|
VERBOSE=
|
||||||
|
fi
|
||||||
|
|
||||||
printf "\n\nRunning tests against PostgreSQL $version\n\n"
|
# Port number: 9.6 -> 50906
|
||||||
export PSYCOPG2_TESTDB=$dbname
|
port=$(( 50000 + $(echo $VERSION \
|
||||||
|
| sed 's/\(.\+\)\.\(.\+\)/100 * \1 + \2/') ))
|
||||||
|
|
||||||
|
printf "\n\nRunning tests against PostgreSQL $VERSION (port $port)\n\n"
|
||||||
|
export PSYCOPG2_TESTDB=$DBNAME
|
||||||
|
export PSYCOPG2_TESTDB_HOST=localhost
|
||||||
export PSYCOPG2_TESTDB_PORT=$port
|
export PSYCOPG2_TESTDB_PORT=$port
|
||||||
export PSYCOPG2_TESTDB_USER=travis
|
export PSYCOPG2_TESTDB_USER=travis
|
||||||
export PSYCOPG2_TEST_REPL_DSN=
|
export PSYCOPG2_TEST_REPL_DSN=
|
||||||
unset PSYCOPG2_TEST_GREEN
|
unset PSYCOPG2_TEST_GREEN
|
||||||
python -c "from psycopg2 import tests; tests.unittest.main(defaultTest='tests.test_suite')"
|
python -c \
|
||||||
|
"from psycopg2 import tests; tests.unittest.main(defaultTest='tests.test_suite')" \
|
||||||
|
$VERBOSE
|
||||||
|
|
||||||
printf "\n\nRunning tests against PostgreSQL $version (green mode)\n\n"
|
printf "\n\nRunning tests against PostgreSQL $VERSION (green mode)\n\n"
|
||||||
export PSYCOPG2_TEST_GREEN=1
|
export PSYCOPG2_TEST_GREEN=1
|
||||||
python -c "from psycopg2 import tests; tests.unittest.main(defaultTest='tests.test_suite')"
|
python -c \
|
||||||
|
"from psycopg2 import tests; tests.unittest.main(defaultTest='tests.test_suite')" \
|
||||||
|
$VERBOSE
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test 9.6 54396
|
# Postgres versions supported by Travis CI
|
||||||
run_test 9.5 54395
|
if [[ -z "$DONT_TEST_PRESENT" ]]; then
|
||||||
run_test 9.4 54394
|
run_test 9.6
|
||||||
run_test 9.3 54393
|
run_test 9.5
|
||||||
run_test 9.2 54392
|
run_test 9.4
|
||||||
|
run_test 9.3
|
||||||
|
run_test 9.2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Unsupported postgres versions that we still support
|
||||||
|
# Images built by https://github.com/psycopg/psycopg2-wheels/tree/build-dinosaurs
|
||||||
|
if [[ -n "$TEST_PAST" ]]; then
|
||||||
|
run_test 7.4
|
||||||
|
run_test 8.0
|
||||||
|
run_test 8.1
|
||||||
|
run_test 8.2
|
||||||
|
run_test 8.3
|
||||||
|
run_test 8.4
|
||||||
|
run_test 9.0
|
||||||
|
run_test 9.1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Postgres built from master
|
||||||
|
if [[ -n "$TEST_FUTURE" ]]; then
|
||||||
|
run_test 10.0
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user