Skip to content

Commit df2f302

Browse files
authored
feat: Introduce dual testing with redis and bitmapist-server (#84)
* feat: Introduce dual testing with redis and bitmapist-server * fix: Stabilize backend connection in tests * chore: Report storage backend in pytest header * chore: ignore bitmapist.db (bitmapist-server artifact) * feat: Refuse to clear data storage if there are more than 20 keys Since the tests now support a previously running instance of the backend, this introduces a protection in case the tests get accidentally connected to production data. * feat: Run CI tests with redis and bitmapist-server * fix(test): Add future annotations import for Python 3.9 type hint compatibility * chore(test): Avoid installing unnecessary dependencies We only need the dev group and: https://docs.astral.sh/uv/concepts/projects/sync/#syncing-development-dependencies > The dev group is special-cased and synced by default.
1 parent b490ef5 commit df2f302

File tree

6 files changed

+413
-58
lines changed

6 files changed

+413
-58
lines changed

.github/workflows/tests.yml

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
timeout-minutes: 60
13-
name: "Python ${{ matrix.python-version }}"
13+
name: "Python ${{ matrix.python-version }} / ${{ matrix.backend }}"
1414
strategy:
1515
matrix:
1616
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
17+
backend: ['redis', 'bitmapist-server']
1718
steps:
1819
- name: Checkout Repo
1920
uses: actions/checkout@v5
@@ -26,11 +27,53 @@ jobs:
2627

2728
- name: Install dependencies
2829
run: |
29-
uv sync --locked --all-extras --dev
30+
uv sync --locked
3031
31-
- name: Install redis
32+
- name: Install Redis
33+
if: matrix.backend == 'redis'
3234
run: |
3335
sudo apt-get install redis -y
3436
37+
- name: Get bitmapist-server latest version
38+
if: matrix.backend == 'bitmapist-server'
39+
id: bitmapist-version
40+
run: |
41+
VERSION=$(curl -s https://api.github.com/repos/Doist/bitmapist-server/releases/latest | jq -r .tag_name)
42+
echo "version=$VERSION" >> $GITHUB_OUTPUT
43+
44+
- name: Cache bitmapist-server
45+
if: matrix.backend == 'bitmapist-server'
46+
id: cache-bitmapist
47+
uses: actions/cache@v4
48+
with:
49+
path: ~/bitmapist-server
50+
key: bitmapist-server-${{ steps.bitmapist-version.outputs.version }}
51+
52+
- name: Download bitmapist-server
53+
if: matrix.backend == 'bitmapist-server' && steps.cache-bitmapist.outputs.cache-hit != 'true'
54+
run: |
55+
wget https://github.com/Doist/bitmapist-server/releases/latest/download/bitmapist-server-linux-amd64.tar.gz
56+
tar -xzf bitmapist-server-linux-amd64.tar.gz
57+
chmod +x bitmapist-server
58+
mv bitmapist-server ~/bitmapist-server
59+
60+
- name: Install bitmapist-server
61+
if: matrix.backend == 'bitmapist-server'
62+
run: |
63+
sudo cp ~/bitmapist-server /usr/local/bin/bitmapist-server
64+
sudo chmod +x /usr/local/bin/bitmapist-server
65+
66+
- name: Verify Redis is available
67+
if: matrix.backend == 'redis'
68+
run: |
69+
command -v redis-server || exit 1
70+
redis-server --version
71+
72+
- name: Verify bitmapist-server is available
73+
if: matrix.backend == 'bitmapist-server'
74+
run: |
75+
command -v bitmapist-server || exit 1
76+
bitmapist-server --version
77+
3578
- name: Run tests
3679
run: uv run pytest -vv

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
*.egg-info
44
/dist
55
.tox
6-
dump.rdb
6+
dump.rdb
7+
bitmapist.db

README.md

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,22 +342,70 @@ uv sync
342342

343343
## Testing
344344

345-
To run our tests will need to ensure a local redis server is installed.
345+
### Quick Start with Docker (Recommended)
346346

347-
You can use these environment variables to tell the tests about Redis:
347+
The easiest way to run tests locally is with Docker:
348348

349-
- `BITMAPIST_REDIS_SERVER_PATH`: Path to the Redis server executable (defaults to the first one in the path or `/usr/bin/redis-server`)
350-
- `BITMAPIST_REDIS_PORT`: Port number for the Redis server (defaults to 6399)
349+
```bash
350+
# Start both backend servers
351+
docker compose up -d
352+
353+
# Run tests
354+
uv run pytest
355+
356+
# Stop servers when done
357+
docker compose down
358+
```
359+
360+
This runs tests against both Redis and bitmapist-server backends automatically.
351361

352-
We use `pytest` to run unit tests, which you can run with:
362+
### Alternative: Native Binaries
353363

364+
To run tests with native binaries, you'll need at least one backend server installed:
365+
366+
**Redis:**
367+
- Install `redis-server` using your package manager
368+
- Ensure it's in your `PATH`, or set `BITMAPIST_REDIS_SERVER_PATH`
369+
370+
**Bitmapist-server:**
371+
- Download from the [releases page](https://github.com/Doist/bitmapist-server/releases)
372+
- Ensure it's in your PATH, or set `BITMAPIST_SERVER_PATH`
373+
374+
Then run:
354375
```bash
355376
uv run pytest
356377
```
357378

358-
> [!TIP]
359-
> You can also run tests against the [bitmapist-server](https://github.com/Doist/bitmapist-server) backend instead of Redis.
360-
> To do this, set the `BITMAPIST_REDIS_SERVER_PATH` variable to the path of the `bitmapist-server` executable.
379+
The test suite auto-detects available backends and runs accordingly:
380+
- **Docker containers running?** Uses them
381+
- **Native binaries available?** Starts them automatically
382+
- **Nothing available?** Shows error
383+
384+
### Configuration
385+
386+
#### Environment Variables
387+
388+
Customize backend locations and ports if needed:
389+
390+
```bash
391+
# Backend binary paths (optional - auto-detected from PATH by default)
392+
export BITMAPIST_REDIS_SERVER_PATH=/custom/path/to/redis-server
393+
export BITMAPIST_SERVER_PATH=/custom/path/to/bitmapist-server
394+
395+
# Backend ports (optional - defaults shown)
396+
export BITMAPIST_REDIS_PORT=6399
397+
export BITMAPIST_SERVER_PORT=6400
398+
```
399+
400+
#### Testing Specific Backends
401+
402+
```bash
403+
# Test only Redis
404+
uv run pytest -k redis
405+
406+
# Test only bitmapist-server
407+
uv run pytest -k bitmapist-server
408+
```
361409

362410
## Releasing new versions
363411

docker-compose.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is used to start the Redis and bitmapist-server services for local
2+
# development and testing.
3+
4+
services:
5+
redis:
6+
image: redis:7-alpine
7+
ports:
8+
- "${BITMAPIST_REDIS_PORT:-6399}:6379"
9+
command: redis-server --port 6379
10+
11+
bitmapist-server:
12+
image: ghcr.io/doist/bitmapist-server:v1.9.8
13+
ports:
14+
- "${BITMAPIST_SERVER_PORT:-6400}:6379"

0 commit comments

Comments
 (0)