Skip to content

Commit

Permalink
add working integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmega committed Dec 4, 2024
1 parent 1261dd0 commit fba13ae
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 35 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:

env:
DOCKER_FILE: bittorrent-benchmarks.Dockerfile
DOCKER_FILE: ./docker/bittorrent-benchmarks.Dockerfile
DOCKER_REPO: codexstorage/bittorrent-benchmarks

jobs:
Expand All @@ -18,6 +18,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Use Docker in rootless mode.
uses: ScribeMD/[email protected]

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Expand Down
3 changes: 2 additions & 1 deletion benchmarks/deluge/deluge_node.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base64
import logging
import shutil
import socket
from dataclasses import dataclass
from io import BytesIO
from pathlib import Path
Expand Down Expand Up @@ -128,7 +129,7 @@ def is_ready(self) -> bool:
try:
self.connect()
return True
except ConnectionRefusedError:
except (ConnectionRefusedError, socket.gaierror):
return False

def _init_folders(self):
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/deluge/tracker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import socket

import requests
from urllib3.util import Url

Expand All @@ -13,5 +15,5 @@ def is_ready(self) -> bool:
try:
requests.get(str(self.announce_url))
return True
except ConnectionError:
except (ConnectionError, socket.gaierror):
return False
24 changes: 0 additions & 24 deletions bittorrent-benchmarks.Dockerfile

This file was deleted.

51 changes: 44 additions & 7 deletions docker-compose.ci.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
# Runs the whole test suite, with the test runner inside a container. This is ideal for CI.
services:
test-runner:
image: bittorrent-benchmarks:test
container_name: test-runner
volumes:
- ./volume:/opt/bittorrent-benchmarks/volume
entrypoint: [ "pytest", "--exitfirst" ]
environment:
- DELUGE_NODE_1=deluge-1
- DELUGE_NODE_2=deluge-2
- DELUGE_NODE_3=deluge-3
- TRACKER_ANNOUNCE_URL=http://tracker:8000/announce
- shared-volume:/opt/bittorrent-benchmarks/volume
entrypoint: [ "bash", "-c", "/opt/bittorrent-benchmarks/docker/bin/run-tests.sh" ]
healthcheck:
test: stat /opt/bittorrent-benchmarks/volume/.initialized
interval: 1s
timeout: 5s
retries: 150

deluge-1:
volumes: !override
- type: volume
source: shared-volume
target: /var/lib/deluge
volume:
subpath: deluge-1
depends_on:
test-runner:
condition: service_healthy

deluge-2:
volumes: !override
- type: volume
source: shared-volume
target: /var/lib/deluge
volume:
subpath: deluge-2
depends_on:
test-runner:
condition: service_healthy

deluge-3:
volumes: !override
- type: volume
source: shared-volume
target: /var/lib/deluge
volume:
subpath: deluge-3
depends_on:
test-runner:
condition: service_healthy

volumes:
shared-volume:
4 changes: 4 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# This compose spec contains the basic setup for running integration tests with the
# test runner outside of a container and bind mounts for data so they can be inspected.
# This is ideal for development.

# You will need [rootless Docker](https://docs.docker.com/engine/security/rootless/)
# for this to work cause the tests rely on user-writable bind mounts.

Expand Down
17 changes: 17 additions & 0 deletions docker/bin/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -e

export DELUGE_NODE_1=deluge-1
export DELUGE_NODE_2=deluge-2
export DELUGE_NODE_3=deluge-3
export TRACKER_ANNOUNCE_URL=http://tracker:8000/announce

# Initializes the shared volume.
echo "Initializing shared volume."
mkdir -p /opt/bittorrent-benchmarks/volume/deluge-{1,2,3}
touch /opt/bittorrent-benchmarks/volume/.initialized

echo "Launching tests."
cd /opt/bittorrent-benchmarks
poetry run pytest --exitfirst

27 changes: 27 additions & 0 deletions docker/bittorrent-benchmarks.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM python:3.12-slim

ARG UID=1000
ARG GID=1000
ARG BUILD_TYPE="test"

RUN groupadd -g ${GID} runner \
&& useradd -u ${UID} -g ${GID} -s /bin/bash -m runner
RUN mkdir /opt/bittorrent-benchmarks && chown -R runner:runner /opt/bittorrent-benchmarks
RUN pip install poetry

USER runner
WORKDIR /opt/bittorrent-benchmarks

COPY --chown=runner:runner pyproject.toml poetry.lock ./
RUN if [ "$BUILD_TYPE" = "production" ]; then \
echo "Image is a production build"; \
poetry install --only main --no-root; \
else \
echo "Image is a test build"; \
poetry install --no-root; \
fi

COPY --chown=runner:runner . .
RUN poetry install --only main

ENTRYPOINT ["poetry", "run", "bittorrent-benchmarks", "/opt/bittorrent-benchmarks/experiments.yaml"]
Loading

0 comments on commit fba13ae

Please sign in to comment.