storj/scripts/test-sim-redis-up-and-down.sh
Ivan Fraixedes 49c8e94480
scripts: Add test Satellite working w/o Redis
Create a storj-sim test that checks that uplinks operations works when
satellite runs and can connect to Redis and when it cannot connect to
simulate a Redis downtime. Also verifies that the satellite can start
despite of Redis being downtime.

This test currently doesn't pass and it will be the one used to verify
the work that has to be done to make sure that the satellite allow the
clients to perform their operations despite of Redis being unavailable.
We require these changes before we deploy any customer face satellite on
a multi-region architecture.

NOTE that this test will be added later on to Jenkins to run this test
every time that we apply changes and at that time we'll see if it has to
be adjusted for being able to run on Jenkins because as it's now it may
not work because the scripts start and stop a Redis docker container.

Change-Id: I22acb22f0ca594583e36b45c88f8c03bac73b329
2021-01-25 16:02:59 +01:00

73 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -Eeuo pipefail
set +x
# Required environment variables
if [ -z "${STORJ_SIM_POSTGRES}" ]; then
echo "STORJ_SIM_POSTGRES environment variable must be set to a non-empty string"
exit 1
fi
# constants
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
readonly SCRIPT_DIR
REDIS_CONTAINER_NAME=storj_sim_redis
readonly REDIS_CONTAINER_NAME
TMP_DIR=$(mktemp -d -t tmp.XXXXXXXXXX)
readonly TMP_DIR
# setup tmpdir for testfiles and cleanup
cleanup() {
trap - EXIT
rm -rf "${TMP_DIR}"
docker container rm -f "${REDIS_CONTAINER_NAME}" >/dev/null 2>&1 || true
}
trap cleanup EXIT
echo "install sim"
make -C "$SCRIPT_DIR"/.. install-sim
echo "overriding default max segment size to 6MiB"
GOBIN="${TMP_DIR}" go install -v -ldflags "-X 'storj.io/uplink.maxSegmentSize=6MiB'" storj.io/storj/cmd/uplink
# use modified version of uplink
export PATH="${TMP_DIR}:${PATH}"
export STORJ_NETWORK_DIR="${TMP_DIR}"
STORJ_NETWORK_HOST4=${STORJ_NETWORK_HOST4:-127.0.0.1}
redis_run() {
local retries=10
docker container run -d -p 6379:6379 --name "${REDIS_CONTAINER_NAME}" redis:5.0-alpine
until docker container exec "${REDIS_CONTAINER_NAME}" redis-cli ping >/dev/null 2>&1 ||
[ ${retries} -eq 0 ]; do
echo "waiting for Redis server to be ready, $((retries--)) remaining attemps..."
sleep 1
done
if [ ${retries} -eq 0 ]; then
echo "aborting, Redis server is not ready after several retrials"
exit 1
fi
}
redis_stop() {
docker container stop "${REDIS_CONTAINER_NAME}"
}
# setup the network
storj-sim --failfast -x --satellites 1 --host "${STORJ_NETWORK_HOST4}" network \
--postgres="${STORJ_SIM_POSTGRES}" --redis="127.0.0.1:6379" setup
# run test that checks that the satellite runs when Redis is up and down
redis_run
storj-sim --failfast -x --satellites 1 --host "${STORJ_NETWORK_HOST4}" network \
--redis="127.0.0.1:6379" test bash "${SCRIPT_DIR}/test-uplink-redis-up-and-down.sh" "${REDIS_CONTAINER_NAME}"
# run test that checks that the satellite runs despite of not being able to connect to Redis
redis_stop
storj-sim --failfast -x --satellites 1 --host "${STORJ_NETWORK_HOST4}" network \
--redis="127.0.0.1:6379" test bash "${SCRIPT_DIR}/test-uplink.sh"