forked from igniterealtime/Openfire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runAioxmppIntegrationTests
executable file
·158 lines (140 loc) · 4.38 KB
/
runAioxmppIntegrationTests
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
#!/usr/bin/env bash
set -euo pipefail
DEBUG=false
LOCAL_RUN=false
DOMAIN='example.org'
HOST='localhost'
usage()
{
echo "Usage: $0 [-d] [-l] [-i IPADDRESS] [-h HOST] [-s DOMAIN]"
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 " -h: The hostname for the Openfire under test (default: localhost)"
echo " -s: The XMPP domain name for the Openfire under test (default: example.org)"
exit 2
}
while getopts dlh:i:s: OPTION "$@"; do
case $OPTION in
d)
DEBUG=true
set -x
;;
l)
LOCAL_RUN=true
;;
h)
HOST="${OPTARG}"
;;
i)
IPADDRESS="${OPTARG}"
;;
s)
DOMAIN="${OPTARG}"
;;
\? ) usage;;
: ) usage;;
* ) usage;;
esac
done
if [[ $LOCAL_RUN == true ]] && [[ $DOMAIN != "example.org" ]]; then
echo "Domain is fixed if launching a local instance. If you have an already-running instance to test against, omit the -l flag (and provide -h 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 [[ $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 setUpAioxmppEnvironment {
AIOXMPPDIR="${BASEDIR}/aioxmpp"
AIOXMPPCONFIG="${AIOXMPPDIR}/openfire-config.ini"
if [ -d "${AIOXMPPDIR}" ]; then
pushd "${AIOXMPPDIR}"
git pull
else
git clone -b devel https://github.com/horazont/aioxmpp "${AIOXMPPDIR}"
pushd "${AIOXMPPDIR}"
fi
which pip3
pip3 install setuptools
pip3 install nose
pip3 install -e .
cat >"${AIOXMPPCONFIG}" <<EOL
[global]
provisioner=aioxmpp.e2etest.provision.AnonymousProvisioner
[aioxmpp.e2etest.provision.AnonymousProvisioner]
domain=$DOMAIN
host=$HOST
port=5222
no_verify=true
quirks=["https://zombofant.net/xmlns/aioxmpp/e2etest/quirks#no-adhoc-ping", "https://zombofant.net/xmlns/aioxmpp/e2etest/quirks#no-xep-0049", "https://zombofant.net/xmlns/aioxmpp/e2etest/quirks#muc-no-333"]
EOL
popd
}
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 runTests {
echo "Starting Integration Tests (using aioxmpp)…"
pushd "${AIOXMPPDIR}"
which python3.9
if [ -d output ]; then rm -Rf output; fi
mkdir output
python3.9 -m aioxmpp.e2etest --e2etest-config="${AIOXMPPCONFIG}" --e2etest-only -e 'test_set_topic' -e 'test_publish_and_purge' -e 'test_publish_multiple_and_get_by_id' tests 2>&1 | tee output/aioxmpp.test.output.txt
if [ ${PIPESTATUS[0]} -ne 0 ]; then false; fi;
popd
}
setBaseDirectory
trap cleanup EXIT
setUpAioxmppEnvironment
if [[ -n "${IPADDRESS-}" ]]; then
setHostsFile
fi
if [[ $LOCAL_RUN == true ]]; then
launchOpenfire
fi
runTests