1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

test: Reduce main sources of overhead in integration tests

The integration tests spend a lot of time on some ancilliary actions,
which slows them down: generating certificates, adding users, and
waiting for things to happen.

To improve the performance of those actions, this patch:

- Makes (most) tests use plain passwords (-20%)
- Adds a certificate cache to reuse certs (-10%)
- Tightens the sleep loops (-5%)

In aggregate, this patch results in a speedup of the integration tests
of ~30-40%.

Note that some of the tests required adjusting the username, because
`chasquid-util user-add` would convert them to lowercase as per PRECIS
mapping.
This commit is contained in:
Alberto Bertogli
2022-11-12 21:01:25 +00:00
parent 4a00a83c23
commit 4d1526e0c8
7 changed files with 46 additions and 20 deletions

View File

@@ -60,7 +60,10 @@ function chasquid_cover() {
"$@"
}
function add_user() {
# Add a user with chasquid-util. Because this is somewhat cryptographically
# intensive, it can slow down the tests significantly, so most of the time we
# use the simpler add_user (below) for testing purposes.
function chasquid-util-user-add() {
CONFDIR="${CONFDIR:-config}"
DOMAIN=$(echo $1 | cut -d @ -f 2)
mkdir -p "${CONFDIR}/domains/$DOMAIN/"
@@ -71,6 +74,18 @@ function add_user() {
>> .add_user_logs
}
function add_user() {
CONFDIR="${CONFDIR:-config}"
USERNAME=$(echo $1 | cut -d @ -f 1)
DOMAIN=$(echo $1 | cut -d @ -f 2)
USERDB="${CONFDIR}/domains/$DOMAIN/users"
mkdir -p "${CONFDIR}/domains/$DOMAIN/"
if ! [ -f "${USERDB}" ] || ! grep -E -q "key:.*${USERNAME}" "${USERDB}"; then
echo "users:{ key: '${USERNAME}' value:{ plain:{ password: '$2' }}}" \
>> "${USERDB}"
fi
}
function dovecot-auth-cli() {
go run ${TBASE}/../../cmd/dovecot-auth-cli/dovecot-auth-cli.go "$@"
}
@@ -160,14 +175,14 @@ function wait_until_ready() {
PORT=$1
while ! bash -c "true < /dev/tcp/localhost/$PORT" 2>/dev/null ; do
sleep 0.1
sleep 0.01
done
}
# Wait for the given file to exist.
function wait_for_file() {
while ! [ -e ${1} ]; do
sleep 0.1
sleep 0.01
done
}
@@ -176,18 +191,29 @@ function wait_until() {
if eval "$@"; then
return 0
fi
sleep 0.05
sleep 0.01
done
}
# Generate certs for the given hostname.
function generate_certs_for() {
CONFDIR="${CONFDIR:-config}"
mkdir -p ${CONFDIR}/certs/${1}/
(
cd ${CONFDIR}/certs/${1}
generate_cert -ca -validfor=1h -host=${1}
)
# Generating certs is takes time and slows the tests down, so we keep
# a little cache that is common to all tests.
CACHEDIR="${TBASE}/../.generate_certs_cache"
mkdir -p "${CACHEDIR}"
touch -d "10 minutes ago" "${CACHEDIR}/.reference"
if [ "${CACHEDIR}/${1}/" -ot "${CACHEDIR}/.reference" ]; then
# Cache miss (either was not there, or was too old).
mkdir -p "${CACHEDIR}/${1}/"
(
cd "${CACHEDIR}/${1}/"
generate_cert -ca -validfor=1h -host=${1}
)
fi
mkdir -p "${CONFDIR}/certs/${1}/"
cp -p "${CACHEDIR}/${1}"/* "${CONFDIR}/certs/${1}/"
}
# Check the Python version, and skip if it's too old.