Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ jobs:
# so linting on fewer versions makes CI faster.
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"

steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9, '3.10', 3.11]
python-version: [3.9, '3.10', 3.11, 3.12]
connection: ['hiredis', 'plain']
redis-stack-version: ['6.2.6-v9', 'latest', 'edge']

Expand Down Expand Up @@ -75,12 +75,12 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
poetry run test-cov
poetry run test-verbose

- name: Run tests
if: matrix.connection != 'plain' || matrix.redis-stack-version != 'latest'
run: |
SKIP_VECTORIZERS=True SKIP_RERANKERS=True poetry run test-cov
SKIP_VECTORIZERS=True SKIP_RERANKERS=True poetry run test-verbose

- name: Run notebooks
if: matrix.connection == 'plain' && matrix.redis-stack-version == 'latest'
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ To run Testcontainers-based tests you need a local Docker installation such as:

Tests w/ vectorizers:
```bash
poetry run test-cov
poetry run test-verbose
```

Tests w/out vectorizers:
```bash
SKIP_VECTORIZERS=true poetry run test-cov
SKIP_VECTORIZERS=true poetry run test-verbose
```

Tests w/out rerankers:
```bash
SKIP_RERANKERS=true poetry run test-cov
SKIP_RERANKERS=true poetry run test-verbose
```

### Documentation
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ check-types:
lint: format check-types

test:
SKIP_RERANKERS=true SKIP_VECTORIZERS=true poetry run test-cov
SKIP_RERANKERS=true SKIP_VECTORIZERS=true poetry run test-verbose

test-all:
poetry run test-cov
poetry run test-verbose

check: lint test

Expand Down
49 changes: 40 additions & 9 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,55 @@


@pytest.fixture(scope="session", autouse=True)
def redis_container():
# Set the default Redis version if not already set
def redis_container(request):
"""
Create a unique Compose project for each xdist worker by setting
COMPOSE_PROJECT_NAME. That prevents collisions on container/volume names.
"""
# In xdist, the config has "workerid" in workerinput. For the main (non-xdist)
# process, 'workerid' is often 'master' or something similar.
worker_id = request.config.workerinput.get("workerid", "master")

# Set the Compose project name so containers do not clash across workers
os.environ["COMPOSE_PROJECT_NAME"] = f"redis_test_{worker_id}"
os.environ.setdefault("REDIS_VERSION", "edge")

compose = DockerCompose("tests", compose_file_name="docker-compose.yml", pull=True)
compose = DockerCompose(
context="tests",
compose_file_name="docker-compose.yml",
pull=True,
)

compose.start()

# If you mapped the container port 6379:6379 in docker-compose.yml,
# you might have collisions across workers. If you rely on ephemeral
# host ports, remove the `ports:` block in docker-compose.yml and do:
redis_host, redis_port = compose.get_service_host_and_port("redis", 6379)
redis_url = f"redis://{redis_host}:{redis_port}"
os.environ["REDIS_URL"] = redis_url
#redis_url = f"redis://{redis_host}:{redis_port}"
#os.environ["REDIS_URL"] = redis_url

yield compose

compose.stop()
# Optionally, clean up the COMPOSE_PROJECT_NAME you set:
os.environ.pop("COMPOSE_PROJECT_NAME", None)


@pytest.fixture(scope="session")
def redis_url():
return os.getenv("REDIS_URL", "redis://localhost:6379")
def redis_url(redis_container):
"""
Use the `DockerCompose` fixture to get host/port of the 'redis' service
on container port 6379 (mapped to an ephemeral port on the host).
"""
host, port = redis_container.get_service_host_and_port("redis", 6379)
return f"redis://{host}:{port}"

@pytest.fixture
async def async_client(redis_url):
"""
An async Redis client that uses the dynamic `redis_url`.
"""
client = await RedisConnectionFactory.get_async_redis_connection(redis_url)
yield client
try:
Expand All @@ -38,8 +66,11 @@ async def async_client(redis_url):
raise

@pytest.fixture
def client():
conn = RedisConnectionFactory.get_redis_connection(os.environ["REDIS_URL"])
def client(redis_url):
"""
A sync Redis client that uses the dynamic `redis_url`.
"""
conn = RedisConnectionFactory.get_redis_connection(redis_url)
yield conn
conn.close()

Expand Down
Loading
Loading