Skip to content

Commit 7f1e22e

Browse files
authored
bump timeout (#8)
Bump timeout and fix unit test
1 parent c789ec6 commit 7f1e22e

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ jobs:
3838
postgres:
3939
# ensure postgres version this stays in sync with prod database
4040
# and with postgres version used in docker compose
41-
image: postgres:16
41+
# Testing with postgres that has the pg vector extension
42+
image: ankane/pgvector
4243
env:
4344
# optional (defaults to `postgres`)
4445
POSTGRES_DB: langchain_test
@@ -67,7 +68,6 @@ jobs:
6768
name: Python ${{ matrix.python-version }} tests
6869
steps:
6970
- uses: actions/checkout@v3
70-
7171
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
7272
uses: "./.github/actions/poetry_setup"
7373
with:
@@ -91,10 +91,14 @@ jobs:
9191
run: |
9292
echo "Running tests, installing dependencies with poetry..."
9393
poetry install --with test,lint,typing,docs
94-
9594
- name: Run tests
9695
run: make test
97-
96+
env:
97+
POSTGRES_DB: langchain_test
98+
POSTGRES_PASSWORD: langchain
99+
POSTGRES_USER: langchain
100+
POSTGRES_HOST: localhost
101+
POSTGRES_PORT: 5432
98102
- name: Ensure the tests did not create any additional files
99103
shell: bash
100104
run: |

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ build-backend = "poetry.core.masonry.api"
7979
# --snapshot-warn-unused Prints a warning on unused snapshots rather than fail the test suite.
8080
addopts = "--strict-markers --strict-config --durations=5"
8181
# Global timeout for all tests. There should be a good reason for a test to
82-
# takemore than 5 seconds.
83-
timeout = 5
82+
# takemore than 30 seconds.
83+
timeout = 30
8484
# Registering custom markers.
8585
# https://docs.pytest.org/en/7.1.x/example/markers.html#registering-markers
86-
markers = [
87-
]
86+
markers = []
8887
asyncio_mode = "auto"
8988

tests/unit_tests/test_vectorstore.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Test PGVector functionality."""
22

3-
import os
43
from typing import Any, Dict, Generator, List
54

65
import pytest
@@ -21,23 +20,9 @@
2120
TYPE_4_FILTERING_TEST_CASES,
2221
TYPE_5_FILTERING_TEST_CASES,
2322
)
23+
from tests.utils import VECTORSTORE_CONNECTION_STRING
2424

25-
# The connection string matches the default settings in the docker-compose file
26-
# located in the root of the repository: [root]/docker/docker-compose.yml
27-
# Non-standard ports are used to avoid conflicts with other local postgres
28-
# instances.
29-
# To spin up postgres with the pgvector extension:
30-
# cd [root]/docker/docker-compose.yml
31-
# docker compose up pgvector
32-
CONNECTION_STRING = PGVector.connection_string_from_db_params(
33-
driver=os.environ.get("TEST_PGVECTOR_DRIVER", "psycopg"),
34-
host=os.environ.get("TEST_PGVECTOR_HOST", "localhost"),
35-
port=int(os.environ.get("TEST_PGVECTOR_PORT", "6024")),
36-
database=os.environ.get("TEST_PGVECTOR_DATABASE", "langchain"),
37-
user=os.environ.get("TEST_PGVECTOR_USER", "langchain"),
38-
password=os.environ.get("TEST_PGVECTOR_PASSWORD", "langchain"),
39-
)
40-
25+
CONNECTION_STRING = VECTORSTORE_CONNECTION_STRING
4126
ADA_TOKEN_COUNT = 1536
4227

4328

@@ -411,7 +396,7 @@ def pgvector() -> Generator[PGVector, None, None]:
411396
store.drop_tables()
412397

413398

414-
@pytest.mark.parametrize("test_filter, expected_ids", TYPE_1_FILTERING_TEST_CASES[:1])
399+
@pytest.mark.parametrize("test_filter, expected_ids", TYPE_1_FILTERING_TEST_CASES)
415400
def test_pgvector_with_with_metadata_filters_1(
416401
pgvector: PGVector,
417402
test_filter: Dict[str, Any],

tests/utils.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,33 @@
55
import psycopg
66
from typing_extensions import AsyncGenerator, Generator
77

8+
# Env variables match the default settings in the docker-compose file
9+
# located in the root of the repository: [root]/docker-compose.yml
10+
# Non-standard ports are used to avoid conflicts with other local postgres
11+
# instances.
12+
# To spint up the postgres service for testing, run:
13+
# cd [root]/docker-compose.yml
14+
# docker-compose up pgvector
815
POSTGRES_USER = os.environ.get("POSTGRES_USER", "langchain")
916
POSTGRES_HOST = os.environ.get("POSTGRES_HOST", "localhost")
1017
POSTGRES_PASSWORD = os.environ.get("POSTGRES_PASSWORD", "langchain")
1118
POSTGRES_DB = os.environ.get("POSTGRES_DB", "langchain")
1219

13-
14-
# Using a different port for testing than the default 5432
15-
# to avoid conflicts with a running PostgreSQL instance
16-
# This port matches the convention in langchain/docker/docker-compose.yml
17-
# To spin up a PostgreSQL instance for testing, run:
18-
# docker-compose -f docker/docker-compose.yml up -d postgres
19-
POSTGRES_PORT = os.environ.get("POSTGRES_PORT", "6023")
20+
POSTGRES_PORT = os.environ.get("POSTGRES_PORT", "6024")
2021

2122
DSN = (
2223
f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}"
2324
f":{POSTGRES_PORT}/{POSTGRES_DB}"
2425
)
2526

27+
# Connection string used primarily by the vectorstores tests
28+
# it's written to work with SQLAlchemy (takes a driver name)
29+
# It is also running on a postgres instance that has the pgvector extension
30+
VECTORSTORE_CONNECTION_STRING = (
31+
f"postgresql+psycopg://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}"
32+
f":{POSTGRES_PORT}/{POSTGRES_DB}"
33+
)
34+
2635

2736
@asynccontextmanager
2837
async def asyncpg_client() -> AsyncGenerator[psycopg.AsyncConnection, None]:

0 commit comments

Comments
 (0)