-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_all_versions.sh
executable file
·131 lines (107 loc) · 3.3 KB
/
test_all_versions.sh
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
set -eu
orig_path=$PATH
newest_version=1.4
unset PGSERVICE
set_path() {
version=$1
export PATH=/usr/lib/postgresql/$version/bin:$orig_path
}
get_port() {
version=$1
pg_lsclusters | awk -v version=$version '$1 == version { print $3 }'
}
make_and_test() {
version=$1
from_version=${2:-$newest_version}
set_path $version
make clean
sudo "PATH=$PATH" make uninstall
sudo "PATH=$PATH" make install
port=$(get_port $version)
PGPORT=$port psql postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'contrib_regression' AND pid <> pg_backend_pid()"
FROMVERSION=$from_version PGPORT=$port make installcheck
sigpg() {
sig=$1
echo "performing $sig"
sudo systemctl $sig postgresql@${version}-main
}
# Start without shared_preload_libraries
echo "Testing no shared_preload_libraries launch and restart"
sudo -u postgres sed -i "s/'pglogical,pglogical_ticker'/'pglogical'/g" /etc/postgresql/$version/main/postgresql.conf
sigpg restart
## Run the first 4 regression files which sets things up
echo "Seeding with first 4 regression scripts"
for f in sql/0[1-4]*; do
PGPORT=$port psql contrib_regression -f $f > /dev/null
done
assert_ticker_running() {
PGPORT=$port psql contrib_regression -v "ON_ERROR_STOP" << 'EOM'
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_stat_activity WHERE application_name LIKE 'pglogical_ticker%') THEN
RAISE EXCEPTION 'No ticker running';
END IF;
END$$;
EOM
echo "PASS"
}
assert_ticker_not_running() {
PGPORT=$port psql contrib_regression -v "ON_ERROR_STOP" << 'EOM'
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM pg_stat_activity WHERE application_name LIKE 'pglogical_ticker%') THEN
RAISE EXCEPTION 'Ticker running';
END IF;
END$$;
EOM
echo "PASS"
}
ticker_check() {
echo "Launching ticker if not launched"
PGPORT=$port psql contrib_regression -v "ON_ERROR_STOP" << 'EOM' > /dev/null
SELECT pglogical_ticker.launch();
SELECT pg_sleep(1);
EOM
assert_ticker_running
echo "Terminating and expecting auto-restart"
PGPORT=$port psql contrib_regression -v "ON_ERROR_STOP" << 'EOM' > /dev/null
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE application_name LIKE 'pglogical_ticker%';
SELECT pg_sleep(11);
EOM
assert_ticker_running
}
ticker_check
# Perform first load using shared_preload_libraries to set GUCs
sudo -u postgres sed -i "s/'pglogical'/'pglogical,pglogical_ticker'/g" /etc/postgresql/$version/main/postgresql.conf
sudo -u postgres sed -i "\$apglogical_ticker.database = 'contrib_regression'" /etc/postgresql/$version/main/postgresql.conf
sigpg reload
ticker_check
# Restart, now it should auto-launch
sigpg restart
sleep 11
ticker_check
echo "Testing soft crash restart"
PGPORT=$port psql contrib_regression -c "SELECT 'i filo postgres'::text, pg_sleep(10);" &
pid=`PGPORT=$port psql contrib_regression -Atq -c "SELECT pid FROM pg_stat_activity WHERE NOT pid = pg_backend_pid() AND query ~* 'i filo postgres'"`
echo "found pid $pid to kill"
sudo kill -9 $pid
sleep 12
ticker_check
sudo -u postgres sed -i "/pglogical_ticker.database/d" /etc/postgresql/$version/main/postgresql.conf
sigpg restart
sleep 11
assert_ticker_not_running
}
test_all_versions() {
from_version="$1"
cat << EOM
*******************FROM VERSION $from_version******************
EOM
make_and_test "9.5"
make_and_test "9.6"
make_and_test "10"
make_and_test "11"
}
test_all_versions "1.4"
test_all_versions "1.3"