Skip to content

Commit b310bed

Browse files
committed
CI/CD: Add Mellium-based integration test to Github workflow
This adds a very basic Mellium-based test to the Github CI workflow. Mellium defines 'proper' integration tests, but its framework for IT is a bit different than what we're used to. Were we typically start a server, and tell a framework to start testing against it, the Mellium framework has hooks where it starts clean servers on demand. Our existing scripts do no facilitate that. To get a ball rolling, this commit introduces a Mellium 'test' that uses an examplebot that's included with Mellium, and make it connect against a running Openfire instance.
1 parent c2d1f97 commit b310bed

File tree

2 files changed

+200
-2
lines changed

2 files changed

+200
-2
lines changed

.github/workflows/continuous-integration-workflow.yml

+49-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
path: |
5151
runIntegrationTests
5252
runAioxmppIntegrationTests
53+
runMelliumIntegrationTests
5354
runConnectivityIntegrationTests
5455
test.gradle
5556
- name: Upload coverage report for 'xmppserver' module
@@ -179,11 +180,57 @@ jobs:
179180
- name: Run smack tests
180181
run: ./runIntegrationTests -d -l -i 127.0.0.1
181182

183+
mellium:
184+
185+
name: Execute Mellium-based CI tests
186+
runs-on: ubuntu-latest
187+
needs: build
188+
189+
steps:
190+
- name: Set JAVA_HOME to use Java 11
191+
run: echo "JAVA_HOME=$(echo $JAVA_HOME_11_X64)" >> $GITHUB_ENV
192+
- name: Download distribution artifact from build job.
193+
uses: actions/download-artifact@v3
194+
with:
195+
name: distribution-java11
196+
path: distribution/target/distribution-base
197+
- name: Download test files from build job.
198+
uses: actions/download-artifact@v3
199+
with:
200+
name: test-files
201+
- name: Fix file permissions
202+
run: |
203+
chmod +x distribution/target/distribution-base/bin/openfire.sh
204+
chmod +x ./runMelliumIntegrationTests
205+
206+
- name: Set up Go
207+
uses: actions/setup-go@v4
208+
209+
- name: Run Mellium tests
210+
env:
211+
XMPP_ADDR: [email protected]
212+
XMPP_PASS: secret
213+
run: ./runMelliumIntegrationTests -d -l -h example.org -i 127.0.0.1
214+
215+
- name: Expose test output
216+
if: always()
217+
uses: actions/upload-artifact@v3
218+
with:
219+
name: mellium test output
220+
path: mellium/output
221+
222+
- name: Expose openfire output
223+
if: always()
224+
uses: actions/upload-artifact@v3
225+
with:
226+
name: openfire logs
227+
path: distribution/target/distribution-base/logs/*
228+
182229
publish-maven:
183230

184231
name: Publish to Maven
185232
runs-on: ubuntu-latest
186-
needs: [aioxmpp, connectivity, smack, check_branch]
233+
needs: [aioxmpp, mellium, connectivity, smack, check_branch]
187234
if: ${{github.repository == 'igniterealtime/Openfire' && github.event_name == 'push' && needs.check_branch.outputs.is_publishable_branch == 'true'}}
188235

189236
steps:
@@ -212,7 +259,7 @@ jobs:
212259
# Based on https://github.com/GabLeRoux/github-actions-examples/blob/e0468ce2731b08bd8b1f7cd09d0b94c541310693/.github/workflows/secret_based_conditions.yml
213260
name: Check if Docker Hub secrets exist
214261
runs-on: ubuntu-latest
215-
needs: [build, aioxmpp, connectivity, smack]
262+
needs: [build, aioxmpp, mellium, connectivity, smack]
216263
outputs:
217264
is_DOCKERHUB_SECRET_set: ${{ steps.checksecret_job.outputs.is_DOCKERHUB_SECRET_set }}
218265
steps:

runMelliumIntegrationTests

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
DEBUG=false
5+
LOCAL_RUN=false
6+
7+
DOMAIN='example.org'
8+
HOST='localhost'
9+
10+
usage()
11+
{
12+
echo "Usage: $0 [-d] [-l] [-i IPADDRESS] [-h HOST] [-s DOMAIN]"
13+
echo " -d: Enable debug mode. Prints commands, and preserves temp directories if used (default: off)"
14+
echo " -l: Launch a local Openfire. (default: off)"
15+
echo " -i: Set a hosts file for the given IP and host (or for example.com if running locally). Reverted at exit."
16+
echo " -h: The hostname for the Openfire under test (default: localhost)"
17+
echo " -s: The XMPP domain name for the Openfire under test (default: example.org)"
18+
exit 2
19+
}
20+
21+
while getopts dlh:i:s: OPTION "$@"; do
22+
case $OPTION in
23+
d)
24+
DEBUG=true
25+
set -x
26+
;;
27+
l)
28+
LOCAL_RUN=true
29+
;;
30+
h)
31+
HOST="${OPTARG}"
32+
;;
33+
i)
34+
IPADDRESS="${OPTARG}"
35+
;;
36+
s)
37+
DOMAIN="${OPTARG}"
38+
;;
39+
\? ) usage;;
40+
: ) usage;;
41+
* ) usage;;
42+
esac
43+
done
44+
45+
if [[ $LOCAL_RUN == true ]] && [[ $DOMAIN != "example.org" ]]; then
46+
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)."
47+
exit 1
48+
fi
49+
50+
function setBaseDirectory {
51+
# Pretty fancy method to get reliable the absolute path of a shell
52+
# script, *even if it is sourced*. Credits go to GreenFox on
53+
# stackoverflow: http://stackoverflow.com/a/12197518/194894
54+
pushd . > /dev/null
55+
SCRIPTDIR="${BASH_SOURCE[0]}";
56+
while [ -h "${SCRIPTDIR}" ]; do
57+
cd "$(dirname "${SCRIPTDIR}")"
58+
SCRIPTDIR="$(readlink "$(basename "${SCRIPTDIR}")")";
59+
done
60+
cd "$(dirname "${SCRIPTDIR}")" > /dev/null
61+
SCRIPTDIR="$(pwd)";
62+
popd > /dev/null
63+
BASEDIR="${SCRIPTDIR}"
64+
cd "${BASEDIR}"
65+
}
66+
67+
function createTempDirectory {
68+
OFTEMPDIR=$(mktemp -d)
69+
}
70+
71+
function cleanup {
72+
if [[ $DEBUG == false && -n "${OFTEMPDIR-}" ]]; then
73+
echo "Removing temp directories"
74+
rm -rf "${OFTEMPDIR}"
75+
fi
76+
if [[ $LOCAL_RUN == true ]]; then
77+
echo "Stopping Openfire"
78+
pkill -f openfire.lib #TODO: Can this be made more future-proof against changes in the start script?
79+
fi
80+
}
81+
82+
function setUpMelliumEnvironment {
83+
MELLIUMDIR="${BASEDIR}/mellium"
84+
AIOXMPPCONFIG="${MELLIUMDIR}/openfire-config.ini"
85+
if [ -d "${MELLIUMDIR}" ]; then
86+
pushd "${MELLIUMDIR}"
87+
git pull
88+
else
89+
git clone -b main https://github.com/mellium/xmpp "${MELLIUMDIR}"
90+
pushd "${MELLIUMDIR}"
91+
fi
92+
popd
93+
}
94+
95+
function setHostsFile {
96+
if [[ -n "${IPADDRESS-}" ]]; then
97+
echo "Setting hosts file for local running. This may prompt for sudo."
98+
sudo /bin/sh -c "echo \"$IPADDRESS $HOST\" >> /etc/hosts"
99+
fi
100+
}
101+
102+
function launchOpenfire {
103+
declare -r OPENFIRE_SHELL_SCRIPT="${BASEDIR}/distribution/target/distribution-base/bin/openfire.sh"
104+
105+
if [[ ! -f "${OPENFIRE_SHELL_SCRIPT}" ]]; then
106+
mvn verify -P ci
107+
fi
108+
109+
rm -f distribution/target/distribution-base/conf/openfire.xml
110+
cp distribution/target/distribution-base/conf/openfire-demoboot.xml \
111+
distribution/target/distribution-base/conf/openfire.xml
112+
113+
echo "Starting Openfire…"
114+
"${OPENFIRE_SHELL_SCRIPT}" &
115+
116+
# Wait 120 seconds for Openfire to open up the web interface and
117+
# assume Openfire is fully operational once that happens (not sure if
118+
# this assumption is correct).
119+
echo "Waiting for Openfire…"
120+
timeout 120 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 0.3; done' localhost 7070
121+
}
122+
123+
function runTests {
124+
echo "Starting Integration Tests (using Mellium)…"
125+
pushd "${MELLIUMDIR}"
126+
if [ -d output ]; then rm -Rf output; fi
127+
mkdir output
128+
129+
pushd "${MELLIUMDIR}/examples/echobot"
130+
go build
131+
./echobot -vv 2>&1 | tee "${MELLIUMDIR}/output/mellium.test.output.txt"
132+
if [ ${PIPESTATUS[0]} -ne 0 ]; then false; fi;
133+
popd
134+
135+
# Mellium's integration test require hooks that will launch new servers on demand. Not currently supported by this script.
136+
# go build
137+
# go test -v -tags "integration" -run Integration ./... 2>&1 | tee output/mellium.test.output.txt
138+
# if [ ${PIPESTATUS[0]} -ne 0 ]; then false; fi;
139+
popd
140+
}
141+
142+
setBaseDirectory
143+
trap cleanup EXIT
144+
setUpMelliumEnvironment
145+
if [[ -n "${IPADDRESS-}" ]]; then
146+
setHostsFile
147+
fi
148+
if [[ $LOCAL_RUN == true ]]; then
149+
launchOpenfire
150+
fi
151+
runTests

0 commit comments

Comments
 (0)