Skip to content

Commit 28551f3

Browse files
update CI/CD to match redisvl flow
1 parent 4fa7350 commit 28551f3

File tree

6 files changed

+57
-65
lines changed

6 files changed

+57
-65
lines changed

.github/workflows/test.yml

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,26 @@ on:
77
branches:
88
- main
99

10+
workflow_dispatch:
11+
1012
env:
1113
POETRY_VERSION: "1.8.3"
1214

1315
jobs:
1416
test:
15-
name: Python ${{ matrix.python-version }} - ${{ matrix.connection }} [redis-stack ${{matrix.redis-stack-version}}]
17+
name: Python ${{ matrix.python-version }} - [redis ${{ matrix.redis-version }}]
1618
runs-on: ubuntu-latest
1719

1820
strategy:
1921
fail-fast: false
2022
matrix:
21-
python-version: [3.9, '3.10', 3.11, 3.12]
22-
connection: ['hiredis', 'plain']
23-
redis-stack-version: ['6.2.6-v9', 'latest', 'edge']
24-
25-
services:
26-
redis:
27-
image: redis/redis-stack-server:${{matrix.redis-stack-version}}
28-
ports:
29-
- 6379:6379
23+
python-version: [3.9, 3.11, 3.13]
24+
redis-version: ['6.2.6-v9', 'latest', '8.0-M03']
3025

3126
steps:
32-
- uses: actions/checkout@v2
27+
- name: Check out repository
28+
uses: actions/checkout@v3
29+
3330
- name: Set up Python ${{ matrix.python-version }}
3431
uses: actions/setup-python@v4
3532
with:
@@ -45,15 +42,22 @@ jobs:
4542
run: |
4643
poetry install --all-extras
4744
48-
- name: Install hiredis if needed
49-
if: matrix.connection == 'hiredis'
45+
- name: Set Redis image name
5046
run: |
51-
poetry add hiredis
52-
53-
- name: Set Redis version
47+
if [[ "${{ matrix.redis-version }}" == "8.0-M03" ]]; then
48+
echo "REDIS_IMAGE=redis:${{ matrix.redis-version }}" >> $GITHUB_ENV
49+
else
50+
echo "REDIS_IMAGE=redis/redis-stack-server:${{ matrix.redis-version }}" >> $GITHUB_ENV
51+
fi
52+
53+
- name: Run API tests
54+
if: matrix.redis-version == 'latest'
55+
env:
56+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
5457
run: |
55-
echo "REDIS_VERSION=${{ matrix.redis-stack-version }}" >> $GITHUB_ENV
58+
make test-all
5659
5760
- name: Run tests
61+
if: matrix.redis-version != 'latest'
5862
run: |
5963
make test

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: install format lint test clean redis-start redis-stop check-types check
1+
.PHONY: install format lint test test-all clean redis-start redis-stop check-types check
22

33
install:
44
poetry install --all-extras
@@ -21,6 +21,9 @@ lint: format check-types
2121
test:
2222
poetry run test-verbose
2323

24+
test-all:
25+
poetry run test-verbose --run-api-tests
26+
2427
check: lint test
2528

2629
clean:

langgraph/store/redis/aio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(
9898
self.configure_client(
9999
redis_url=redis_url,
100100
redis_client=redis_client,
101-
connection_args=connection_args or {}
101+
connection_args=connection_args or {},
102102
)
103103

104104
# Create store index

scripts.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import subprocess
2+
import sys
23

34

45
def format():
@@ -29,10 +30,18 @@ def check_mypy():
2930

3031

3132
def test():
32-
subprocess.run(["python", "-m", "pytest", "-n", "auto", "--log-level=CRITICAL"], check=True)
33+
test_cmd = ["python", "-m", "pytest", "-n", "auto", "--log-level=CRITICAL"]
34+
# Get any extra arguments passed to the script
35+
extra_args = sys.argv[1:]
36+
if extra_args:
37+
test_cmd.extend(extra_args)
38+
subprocess.run(test_cmd, check=True)
3339

3440

3541
def test_verbose():
36-
subprocess.run(
37-
["python", "-m", "pytest", "-n", "auto", "-vv", "-s", "--log-level=CRITICAL"], check=True
38-
)
42+
test_cmd = ["python", "-m", "pytest", "-n", "auto", "-vv", "-s", "--log-level=CRITICAL"]
43+
# Get any extra arguments passed to the script
44+
extra_args = sys.argv[1:]
45+
if extra_args:
46+
test_cmd.extend(extra_args)
47+
subprocess.run(test_cmd, check=True)

tests/conftest.py

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import subprocess
32

43
import pytest
54
from redis.asyncio import Redis
@@ -8,55 +7,28 @@
87

98
VECTOR_TYPES = ["vector", "halfvec"]
109

11-
# try:
12-
# from testcontainers.compose import DockerCompose
13-
14-
# TESTCONTAINERS_AVAILABLE = True
15-
# except ImportError:
16-
# TESTCONTAINERS_AVAILABLE = False
17-
18-
# if TESTCONTAINERS_AVAILABLE:
19-
2010

2111
@pytest.fixture(autouse=True)
2212
def set_tokenizers_parallelism():
2313
"""Disable tokenizers parallelism in tests to avoid deadlocks"""
2414
os.environ["TOKENIZERS_PARALLELISM"] = "false"
2515

26-
# @pytest.fixture(scope="session", autouse=True)
27-
# def redis_container() -> DockerCompose:
28-
# # Set the default Redis version if not already set
29-
# os.environ.setdefault("REDIS_VERSION", "edge")
30-
31-
# try:
32-
# compose = DockerCompose(
33-
# "tests", compose_file_name="docker-compose.yml", pull=True
34-
# )
35-
# compose.start()
36-
37-
# redis_host, redis_port = compose.get_service_host_and_port("redis", 6379)
38-
# redis_url = f"redis://{redis_host}:{redis_port}"
39-
# os.environ["DEFAULT_REDIS_URI"] = redis_url
40-
41-
# yield compose
42-
43-
# compose.stop()
44-
# except subprocess.CalledProcessError:
45-
# yield None
46-
4716

4817
@pytest.fixture(scope="session", autouse=True)
4918
def redis_container(request):
5019
"""
51-
Create a unique Compose project for each xdist worker by setting
52-
COMPOSE_PROJECT_NAME. That prevents collisions on container/volume names.
20+
If using xdist, create a unique Compose project for each xdist worker by
21+
setting COMPOSE_PROJECT_NAME. That prevents collisions on container/volume
22+
names.
5323
"""
5424
# In xdist, the config has "workerid" in workerinput
55-
worker_id = request.config.workerinput.get("workerid", "master")
25+
workerinput = getattr(request.config, "workerinput", {})
26+
worker_id = workerinput.get("workerid", "master")
27+
5628

5729
# Set the Compose project name so containers do not clash across workers
5830
os.environ["COMPOSE_PROJECT_NAME"] = f"redis_test_{worker_id}"
59-
os.environ.setdefault("REDIS_VERSION", "edge")
31+
os.environ.setdefault("REDIS_IMAGE", "redis/redis-stack-server:latest")
6032

6133
compose = DockerCompose(
6234
context="tests",
@@ -70,11 +42,6 @@ def redis_container(request):
7042
compose.stop()
7143

7244

73-
# @pytest.fixture(scope="session")
74-
# def redis_url() -> str:
75-
# return os.getenv("DEFAULT_REDIS_URI", "redis://localhost:6379")
76-
77-
7845
@pytest.fixture(scope="session")
7946
def redis_url(redis_container):
8047
"""
@@ -85,6 +52,15 @@ def redis_url(redis_container):
8552
return f"redis://{host}:{port}"
8653

8754

55+
@pytest.fixture
56+
async def async_client(redis_url):
57+
"""
58+
An async Redis client that uses the dynamic `redis_url`.
59+
"""
60+
async with await RedisConnectionFactory._get_aredis_connection(redis_url) as client:
61+
yield client
62+
63+
8864
@pytest.fixture
8965
def client(redis_url):
9066
"""

tests/test_shallow_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from typing import Any, AsyncGenerator, Dict
22

33
import pytest
4-
from redis.asyncio import Redis
5-
from redis.exceptions import ConnectionError as RedisConnectionError
64
from langchain_core.runnables import RunnableConfig
75
from langgraph.checkpoint.base import (
86
Checkpoint,
97
CheckpointMetadata,
108
create_checkpoint,
119
empty_checkpoint,
1210
)
11+
from redis.asyncio import Redis
12+
from redis.exceptions import ConnectionError as RedisConnectionError
1313

1414
from langgraph.checkpoint.redis.ashallow import AsyncShallowRedisSaver
1515

0 commit comments

Comments
 (0)