Skip to content

Commit

Permalink
ci: test against redis 6 (apt install) and 7 (snap install)
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Jan 25, 2024
1 parent 13ec1fe commit 3ea3056
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
31 changes: 26 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,24 @@ jobs:

# Test each backend that requires a python client against a modern
# version of python to ensure clients are compatible.
#
# - About redis versions:
# redis can be installed from source, as an ubuntu distribution, or
# snap package. To avoid complexity we don't build from source, but we
# test against the ubuntu and snap package, where the ubuntu package
# typically is behind the snap package.
#
# redis-test-version is provided as a matrix input only to provide
# visibility via github's web UI.
#
- python: "3.12"
backend: redis
# redis-test-version is tied to ubuntu's package, so we only test
# redis 6 currently while redis 7 is out, see
# https://packages.ubuntu.com/jammy/redis-server
install-via: apt # version 6.0.16 in ubuntu 22.04, https://packages.ubuntu.com/jammy/redis-server
redis-test-version: "6.0.16?"
- python: "3.12"
backend: redis
install-via: snap # version 7.2.4 or higher, https://snapcraft.io/redis
redis-test-version: ">=7.2.4"
- python: "3.12"
backend: etcd
etcd-test-version: "v3.4.29" # https://github.com/etcd-io/etcd/releases
Expand Down Expand Up @@ -103,10 +116,18 @@ jobs:
etcdctl version
- name: Install redis
- name: Install redis via ${{ matrix.install-via }}
if: matrix.backend == 'redis'
run: |
sudo apt-get -y install redis-server
if [[ "${{ matrix.install-via }}" == "apt" ]]; then
sudo apt-get -y install redis-server
redis-server --version
else
sudo snap install redis
redis.sentinel --version
fi
- name: Run tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion docs/source/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ If you want to use a key-value store to mediate configuration
(mainly for use in distributed deployments, such as containers),
you can get the key-value stores via their respective installation pages:
- Install [`redis-server`](https://redis.io/docs/install/install-redis/)
- Install [`redis`](https://redis.io/docs/install/install-redis/)
- Install [`etcd`](https://github.com/etcd-io/etcd/releases)
Expand Down
7 changes: 6 additions & 1 deletion docs/source/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ This is an example setup for using JupyterHub and TraefikRedisProxy managed by a
2. Start a single-node Redis cluster on the default port on localhost. e.g.:

```bash
$ redis-server
# for redis installed via apt
redis-server

# for redis installed via snap
touch /tmp/redis.conf
redis.sentinel /tmp/redis.conf
```

3. Create a traefik static configuration file, _traefik.toml_, e.g:.
Expand Down
17 changes: 14 additions & 3 deletions performance/perf_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import asyncio
import logging
import shutil
import sys
import textwrap
import time
Expand All @@ -9,7 +10,7 @@
from multiprocessing import cpu_count
from pathlib import Path
from subprocess import Popen
from tempfile import TemporaryDirectory
from tempfile import NamedTemporaryFile, TemporaryDirectory

import aiohttp
import numpy as np
Expand Down Expand Up @@ -176,8 +177,18 @@ def redis():
"""Context manager for running redis-server"""
from redis import Redis

with TemporaryDirectory() as td:
p = Popen(['redis-server'], cwd=td)
with TemporaryDirectory() as td, NamedTemporaryFile as config_file:
if shutil.which("redis-server"):
# redis-server is available when installed via an apt package
redis_server_command = ['redis-server']
elif shutil.which("redis.sentinel"):
# redis.sentinel is available when installed via an snap package
# here we need to provide a config file explicitly
redis_server_command = ['redis.sentinel', config_file.name]
else:
raise ValueError("redis-server or redis.sentinel binaries not on path")

p = Popen(redis_server_command, cwd=td)
for i in range(5):
try:
r = Redis()
Expand Down
18 changes: 14 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import subprocess
import sys
from pathlib import Path
from tempfile import TemporaryDirectory
from tempfile import NamedTemporaryFile, TemporaryDirectory
from urllib.parse import urlparse

import pytest
Expand Down Expand Up @@ -770,11 +770,21 @@ async def _check_consul():

@pytest.fixture(scope="module")
def launch_redis():
with TemporaryDirectory() as path:
with TemporaryDirectory() as path, NamedTemporaryFile as config_file:
if shutil.which("redis-server"):
# redis-server is available when installed via an apt package
redis_server_command = ['redis-server']
elif shutil.which("redis.sentinel"):
# redis.sentinel is available when installed via an snap package
# here we need to provide a config file explicitly
redis_server_command = ['redis.sentinel', config_file.name]
else:
raise ValueError("redis-server or redis.sentinel binaries not on path")

print(f"Launching redis in {path}")
redis_proc = subprocess.Popen(
[
"redis-server",
redis_server_command
+ [
"--port",
str(Config.redis_port),
"--",
Expand Down

0 comments on commit 3ea3056

Please sign in to comment.