Files
scylladb/test/redis/run
Nadav Har'El ca46c3ba8f test/redis: replace run script with shorter Python script
In the past, we had very similar shell scripts for test/alternator/run,
test/cql-pytest/run and test/redis/run. Most of the code of all three
scripts was identical - dealing with starting Scylla in a temporary
directory, running pytest, and so on. The code duplication meant that
every time we fixed a bug in one of those scripts, or added an important
boot-time parameter to Scylla, we needed to fix all three scripts.

The solution was to convert the run scripts to Python, and to use a
common library, test/cql-pytest/run.py, for the main features shared
by all scripts - starting Scylla, waiting for protocols to be available,
and running pytest.

However, we only did this conversion for alternator and cql-pytest -
redis remained the old shell scripts. This patch completes the
conversion also for redis. As expected, no change was needed to the
run.py library code, which was already strong enough for the needs of
the redis tests.

Fixes #9748.

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
Message-Id: <20211207081423.1187847-1-nyh@scylladb.com>
2021-12-07 12:18:07 +02:00

52 lines
1.6 KiB
Python
Executable File

#!/usr/bin/env python3
# Use the run.py library from ../cql-pytest:
import sys
sys.path.insert(1, sys.path[0] + '/../cql-pytest')
import run
import redis
print('Scylla is: ' + run.scylla + '.')
REDIS_PORT = 6379
# run_redis_cmd runs the same as run_scylla_cmd with *additional*
# parameters, so in particular both CQL and Reds APIs will be enabled.
def run_redis_cmd(pid, dir):
(cmd, env) = run.run_scylla_cmd(pid, dir)
ip = run.pid_to_ip(pid)
cmd += [
'--redis-port', str(REDIS_PORT),
]
return (cmd, env)
pid = run.run_with_temporary_dir(run_redis_cmd)
ip = run.pid_to_ip(pid)
# Wait for both CQL and Redis APIs to become responsive. We obviously
# need the Redis API to test Redis, and currently we don't really need
# the CQL API, but maybe in the future we'll want it, so let's be prepared.
def check_redis(ip, port):
try:
r = redis.Redis(ip, port, decode_responses=True)
assert r.ping() == True
except redis.exceptions.ConnectionError:
raise run.NotYetUp
# Any other exception may indicate a problem, and is passed to the caller.
run.wait_for_services(pid, [
lambda: run.check_cql(ip),
lambda: check_redis(ip, REDIS_PORT),
])
# Finally run pytest:
success = run.run_pytest(sys.path[0], ['--redis-host', ip, '--redis-port', str(REDIS_PORT)] + sys.argv[1:])
run.summary = 'Redis tests pass' if success else 'Redis tests failure'
exit(0 if success else 1)
# Note that the run.cleanup_all() function runs now, just like on any exit
# for any reason in this script. It will delete the temporary files and
# announce the failure or success of the test (printing run.summary).