File: test_pgsql.sh

package info (click to toggle)
libdbi-drivers 0.9.0-9
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 6,708 kB
  • sloc: ansic: 19,033; sh: 10,942; xml: 2,759; makefile: 583
file content (99 lines) | stat: -rwxr-xr-x 3,013 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
#
# test_mysql.sh - runs libdbi test suite for PGSQL driver using a temporary
# PGSQL server environment that doesn't distrubs any running PGSQL server.
#
# Copyright (C) 2010 Clint Byrum <clint@ubuntu.com>
# Copyright (C) 2010 Thomas Goirand <zigo@debian.org>
#
# This script is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# This script is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to:
# The Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA

set -e

MYUSER=`whoami`

# initdb refuses to run as root
if [ "${MYUSER}" = "root" ] ; then
	echo dropping root privs..
	exec /bin/su postgres -- "$0" "$@"
fi

MYTMPDIR=`mktemp -d`
BINDIR=`pg_config --bindir`

# depends on language-pack-en | language-pack-en
# because initdb acquires encoding from locale
export LC_ALL="en_US.UTF-8"
${BINDIR}/initdb -D ${MYTMPDIR}
${BINDIR}/postgres -D ${MYTMPDIR} -h '' -k ${MYTMPDIR} &
attempts=0
while ! [ -e ${MYTMPDIR}/postmaster.pid ] ; do
	attempts=$((attempts+1))
	if [ "${attempts}" -gt 10 ] ; then
		echo "skipping test, postgres pid file was not created after 30 seconds"
		exit 0
	fi                                        
	sleep 3
	echo `date`: retrying..
done

# Set the env. var so that pgsql client doesn't use networking
# libpq uses this for all host params if not explicitly passed
export PGHOST=${MYTMPDIR}

# Create a new test db in our own temp env to check that everything
# is working as expected.
if ! createdb -e libdbitest ; then
	echo "Skipping postgres test as libdbitest database creation failed"
	exit 0
fi
dropdb -e libdbitest

# Finaly, run the libdbi pgsql test app
if [ ${MYUSER} != postgres ] ; then
	createdb -e ${MYUSER}
fi
psql -e -c "ALTER USER \"${MYUSER}\" WITH PASSWORD 'abcdefg'"
( echo i; \
	echo n; \
	echo ./drivers/pgsql/.libs; \
	echo pgsql;
	echo ${MYUSER}; \
	echo "abcdefg"; \
	echo ${MYTMPDIR}; \
	echo libdbitest; \
	) | ./tests/test_dbi
#/bin/sh debian/run_test_driver.sh pgsql ${MYUSER} "abcdefg" "127.0.0.2" libdbitest
ecode=$?

# Kill the postgress process and wait of it to shutdown
$BINDIR/pg_ctl stop -D ${MYTMPDIR}
wait

# Make sure it's really stopped, as it seems it sometimes not (see #673086).
if [ -e ${MYTMPDIR}/postmaster.pid ] ; then
	# Allow a graceful delay
	sleep 5
fi
if [ -e ${MYTMPDIR}/postmaster.pid ] ; then
	echo "PG is still running: trying to kill the process"
	POST_PID=`head -n 1 /tmp/tmp.TVsnvwwbab/postmaster.pid`
	kill $POST_PID || true
fi

# Clean up and exit
rm -rf $MYTMPDIR
exit $ecode