forked from igniterealtime/Openfire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runIntegrationTests
executable file
·208 lines (183 loc) · 6.15 KB
/
runIntegrationTests
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env bash
set -euo pipefail
SMACK_VERSION="4.4.2"
GRADLE_VERSION="6.3"
FORCE_CUSTOM_GRADLE=true
CURL_ARGS="--location --silent"
DEBUG=false
LOCAL_RUN=false
HOST='example.org'
ADMINUSER='admin'
ADMINPASS='admin'
usage()
{
echo "Usage: $0 [-d] [-l] [-g] [-i IPADDRESS] [-s SMACK_VERSION] [-h HOST] [-u USERNAME] [-p PASSWORD]"
echo " -d: Enable debug mode. Prints commands, and preserves temp directories if used (default: off)"
echo " -l: Launch a local Openfire. (default: off)"
echo " -i: Set a hosts file for the given IP and host (or for example.com if running locally). Reverted at exit."
echo " -g: Use system Gradle, rather than use the known-good (default: off)"
echo " -s: Set Smack to the given version (default: ${SMACK_VERSION})"
echo " -h: The hostname for the Openfire under test (default: example.org)"
echo " -u: Admin username for Openfire (default: admin)"
echo " -p: Admin password for Openfire (default: admin)"
exit 2
}
while getopts dlgs:h:i:u:p: OPTION "$@"; do
case $OPTION in
d)
DEBUG=true
set -x
;;
l)
LOCAL_RUN=true
;;
g)
FORCE_CUSTOM_GRADLE=false
;;
s)
SMACK_VERSION="${OPTARG}"
;;
h)
HOST="${OPTARG}"
;;
i)
IPADDRESS="${OPTARG}"
;;
u)
ADMINUSER="${OPTARG}"
;;
p)
ADMINPASS="${OPTARG}"
;;
\? ) usage;;
: ) usage;;
* ) usage;;
esac
done
if [[ $LOCAL_RUN == true ]] && [[ $HOST != "example.org" ]]; then
echo "Host is fixed if launching a local instance. If you have an already-running instance to test against, omit the -l flag (and provide -i 127.0.0.1 if necessary)."
exit 1
fi
function setBaseDirectory {
# Pretty fancy method to get reliable the absolute path of a shell
# script, *even if it is sourced*. Credits go to GreenFox on
# stackoverflow: http://stackoverflow.com/a/12197518/194894
pushd . > /dev/null
SCRIPTDIR="${BASH_SOURCE[0]}";
while [ -h "${SCRIPTDIR}" ]; do
cd "$(dirname "${SCRIPTDIR}")"
SCRIPTDIR="$(readlink "$(basename "${SCRIPTDIR}")")";
done
cd "$(dirname "${SCRIPTDIR}")" > /dev/null
SCRIPTDIR="$(pwd)";
popd > /dev/null
BASEDIR="${SCRIPTDIR}"
cd "${BASEDIR}"
}
function createTempDirectory {
OFTEMPDIR=$(mktemp -d)
}
function cleanup {
if [[ $DEBUG == false && -n "${OFTEMPDIR-}" ]]; then
echo "Removing temp directories"
rm -rf "${OFTEMPDIR}"
fi
if [[ -n "${IPADDRESS-}" ]]; then
echo "Resetting hosts file after local running. This may prompt for sudo."
sudo sed -i'.original' "/$IPADDRESS $HOST/d" /etc/hosts
fi
if [[ $LOCAL_RUN == true ]]; then
echo "Stopping Openfire"
pkill -f openfire.lib #TODO: Can this be made more future-proof against changes in the start script?
fi
}
function setUpGradleEnvironment {
if command -v gradle &> /dev/null; then
GRADLE_IN_PATH=true
else
GRADLE_IN_PATH=false
fi
if [[ $GRADLE_IN_PATH == false ]] || $FORCE_CUSTOM_GRADLE; then
createTempDirectory
GRADLEDIR="${OFTEMPDIR}/gradle"
mkdir "${GRADLEDIR}"
pushd "${GRADLEDIR}"
declare -r GRADLE_ZIP="gradle-${GRADLE_VERSION}-bin.zip"
curl ${CURL_ARGS} --output ${GRADLE_ZIP} "https://services.gradle.org/distributions/${GRADLE_ZIP}"
unzip "${GRADLE_ZIP}"
GRADLE="${GRADLEDIR}/gradle-${GRADLE_VERSION}/bin/gradle"
popd
else
GRADLE="gradle"
fi
}
function setHostsFile {
if [[ -n "${IPADDRESS-}" ]]; then
echo "Setting hosts file for local running. This may prompt for sudo."
sudo /bin/sh -c "echo \"$IPADDRESS $HOST\" >> /etc/hosts"
fi
}
function launchOpenfire {
declare -r OPENFIRE_SHELL_SCRIPT="${BASEDIR}/distribution/target/distribution-base/bin/openfire.sh"
if [[ ! -f "${OPENFIRE_SHELL_SCRIPT}" ]]; then
mvn verify -P ci
fi
rm -f distribution/target/distribution-base/conf/openfire.xml
cp distribution/target/distribution-base/conf/openfire-demoboot.xml \
distribution/target/distribution-base/conf/openfire.xml
echo "Starting Openfire…"
"${OPENFIRE_SHELL_SCRIPT}" &
# Wait 120 seconds for Openfire to open up the web interface and
# assume Openfire is fully operational once that happens (not sure if
# this assumption is correct).
echo "Waiting for Openfire…"
timeout 120 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 0.3; done' localhost 7070
}
function runTestsInGradle {
echo "Starting Integration Tests (using Smack ${SMACK_VERSION})…"
DISABLED_INTEGRATION_TESTS=()
# The three tests below suffer from a race conditaion, making them flap. See https://github.com/igniterealtime/Smack/pull/440
DISABLED_INTEGRATION_TESTS+=(MoodIntegrationTest)
DISABLED_INTEGRATION_TESTS+=(UserTuneIntegrationTest)
DISABLED_INTEGRATION_TESTS+=(GeolocationIntegrationTest)
# Occasionally fails, disabled until cause can be found.
DISABLED_INTEGRATION_TESTS+=(XmppConnectionIntegrationTest)
DISABLED_INTEGRATION_TESTS+=(StreamManagementTest)
DISABLED_INTEGRATION_TESTS+=(WaitForClosingStreamElementTest)
DISABLED_INTEGRATION_TESTS+=(IoTControlIntegrationTest)
DISABLED_INTEGRATION_TESTS+=(ModularXmppClientToServerConnectionLowLevelIntegrationTest)
DISABLED_INTEGRATION_TESTS+=(EntityCapsTest)
SINTTEST_DISABLED_TESTS_ARGUMENT="-Dsinttest.disabledTests="
for disabledTest in "${DISABLED_INTEGRATION_TESTS[@]}"; do
SINTTEST_DISABLED_TESTS_ARGUMENT+="${disabledTest},"
done
# Remove last ',' from the argument. Can't use ${SINTTEST_DISABLED_TESTS_ARGUMENT::-1} because bash on MacOS is infuriatingly incompatible.
SINTTEST_DISABLED_TESTS_ARGUMENT="${SINTTEST_DISABLED_TESTS_ARGUMENT:0:$((${#SINTTEST_DISABLED_TESTS_ARGUMENT}-1))}"
$GRADLE --console=plain \
--build-file test.gradle \
-PsmackVersion="${SMACK_VERSION}" \
-q dependencies
$GRADLE --console=plain \
--stacktrace \
run \
-b test.gradle \
-PsmackVersion="${SMACK_VERSION}" \
-Dsinttest.service="${HOST}" \
-Dsinttest.securityMode=disabled \
-Dsinttest.replyTimeout=60000 \
-Dsinttest.adminAccountUsername="${ADMINUSER}" \
-Dsinttest.adminAccountPassword="${ADMINPASS}" \
-Dsinttest.enabledConnections=tcp \
-Dsinttest.dnsResolver=javax \
${SINTTEST_DISABLED_TESTS_ARGUMENT}
}
setBaseDirectory
trap cleanup EXIT
setUpGradleEnvironment
if [[ -n "${IPADDRESS-}" ]]; then
setHostsFile
fi
if [[ $LOCAL_RUN == true ]]; then
launchOpenfire
fi
runTestsInGradle