Skip to content

Commit 67b3950

Browse files
authored
chore(tests): fix many mainline test issues (#190)
* chore(tests): fix many mainline test issues 1) test_spanner_vector_store's dependency on HNLoader fails - use a different loader 2) test_spanner_vector_store's add_document failed with PK size exceeded (this is due to 1, the loader now returns slightly longer content) - use a different url 3) test_spanner_loader doesn't properly clean up the test so that now testing database has too many tables - add cleanup for these tests * Fix cleanup code * Switch to new test databases The old databases are extremely slow due to too many schema objects Also verified pytest test/integrations/ properly cleaned up upon test completion
1 parent e03b316 commit 67b3950

3 files changed

Lines changed: 52 additions & 15 deletions

File tree

integration.cloudbuild.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ steps:
3636
timeout: "7200s"
3737
substitutions:
3838
_INSTANCE_ID: test-instance
39-
_GOOGLE_DATABASE: test-google-db
40-
_PG_DATABASE: test-pg-db
39+
_GOOGLE_DATABASE: test-gsql-db
40+
_PG_DATABASE: test-pgsql-db
4141
_VERSION: "3.9"
4242

4343
options:

tests/integration/test_spanner_loader.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,41 @@ def client() -> Client:
3535
return Client(project=project_id)
3636

3737

38+
@pytest.fixture(scope="class")
39+
def cleanupGSQL(client):
40+
yield
41+
42+
print("\nPerforming GSQL cleanup after each test...")
43+
44+
database = client.instance(instance_id).database(google_database)
45+
operation = database.update_ddl(
46+
[
47+
f"DROP TABLE IF EXISTS {table_name}",
48+
]
49+
)
50+
operation.result(OPERATION_TIMEOUT_SECONDS)
51+
52+
# Code to perform teardown after each test goes here
53+
print("\nGSQL Cleanup complete.")
54+
55+
56+
@pytest.fixture(scope="class")
57+
def cleanupPGSQL(client):
58+
yield
59+
60+
print("\nPerforming PGSQL cleanup after each test...")
61+
62+
database = client.instance(instance_id).database(pg_database)
63+
operation = database.update_ddl([f"DROP TABLE IF EXISTS {table_name}"])
64+
operation.result(OPERATION_TIMEOUT_SECONDS)
65+
66+
# Code to perform teardown after each test goes here
67+
print("\n PGSQL Cleanup complete.")
68+
69+
3870
class TestSpannerDocumentLoaderGoogleSQL:
3971
@pytest.fixture(autouse=True, scope="class")
40-
def setup_database(self, client):
72+
def setup_database(self, client, cleanupGSQL):
4173
database = client.instance(instance_id).database(google_database)
4274
operation = database.update_ddl([f"DROP TABLE IF EXISTS {table_name}"])
4375
operation.result(OPERATION_TIMEOUT_SECONDS)
@@ -455,7 +487,7 @@ def test_loader_custom_json_metadata(self, client):
455487

456488
class TestSpannerDocumentLoaderPostgreSQL:
457489
@pytest.fixture(autouse=True, scope="class")
458-
def setup_database(self, client):
490+
def setup_database(self, client, cleanupPGSQL):
459491
database = client.instance(instance_id).database(pg_database)
460492
operation = database.update_ddl([f"DROP TABLE IF EXISTS {table_name}"])
461493
operation.result(OPERATION_TIMEOUT_SECONDS)
@@ -872,15 +904,15 @@ def test_loader_custom_json_metadata(self, client):
872904

873905
class TestSpannerDocumentSaver:
874906
@pytest.fixture(name="google_client")
875-
def setup_google_client(self, client) -> Client:
907+
def setup_google_client(self, client, cleanupGSQL) -> Client:
876908
database = client.instance(instance_id).database(google_database)
877909
operation = database.update_ddl([f"DROP TABLE IF EXISTS {table_name}"])
878910
print("table dropped")
879911
operation.result(OPERATION_TIMEOUT_SECONDS)
880912
yield client
881913

882914
@pytest.fixture(name="pg_client")
883-
def setup_pg_client(self, client) -> Client:
915+
def setup_pg_client(self, client, cleanupPGSQL) -> Client:
884916
database = client.instance(instance_id).database(pg_database)
885917
operation = database.update_ddl([f"DROP TABLE IF EXISTS {table_name}"])
886918
operation.result(OPERATION_TIMEOUT_SECONDS)

tests/integration/test_spanner_vector_store.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import pytest
2222
from google.cloud.spanner import Client # type: ignore
23-
from langchain_community.document_loaders import HNLoader
23+
from langchain_community.document_loaders import RecursiveUrlLoader
2424
from langchain_community.embeddings import FakeEmbeddings
2525

2626
from langchain_google_spanner.vector_store import ( # type: ignore
@@ -245,11 +245,13 @@ def setup_database(self, client):
245245
id_column="row_id",
246246
metadata_columns=[
247247
TableColumn(name="metadata", type="JSON", is_null=True),
248-
TableColumn(name="title", type="STRING(MAX)", is_null=False),
248+
TableColumn(name="title", type="STRING(MAX)"),
249249
],
250250
)
251251

252-
loader = HNLoader("https://news.ycombinator.com/item?id=34817881")
252+
loader = RecursiveUrlLoader(
253+
"https://news.ycombinator.com/item?id=1", max_depth=1
254+
)
253255

254256
embeddings = FakeEmbeddings(size=3)
255257

@@ -327,7 +329,7 @@ def test_spanner_vector_delete_data(self, setup_database):
327329

328330
docs = loader.load()
329331

330-
deleted = db.delete(documents=[docs[0], docs[1]])
332+
deleted = db.delete(documents=docs)
331333

332334
assert deleted
333335

@@ -459,7 +461,9 @@ def setup_database(self, client):
459461
],
460462
)
461463

462-
loader = HNLoader("https://news.ycombinator.com/item?id=34817881")
464+
loader = RecursiveUrlLoader(
465+
"https://news.ycombinator.com/item?id=1", max_depth=1
466+
)
463467
embeddings = FakeEmbeddings(size=title_vector_size)
464468

465469
def cleanup_db():
@@ -552,7 +556,7 @@ def test_delete(self, setup_database):
552556
)
553557

554558
docs = loader.load()
555-
deleted = db.delete(documents=[docs[0], docs[1]])
559+
deleted = db.delete(documents=docs)
556560

557561
assert deleted
558562

@@ -677,8 +681,9 @@ def setup_database(self, client):
677681
],
678682
)
679683

680-
loader = HNLoader("https://news.ycombinator.com/item?id=34817881")
681-
684+
loader = RecursiveUrlLoader(
685+
"https://news.ycombinator.com/item?id=1", max_depth=1
686+
)
682687
embeddings = FakeEmbeddings(size=3)
683688

684689
yield loader, embeddings
@@ -755,7 +760,7 @@ def test_spanner_vector_delete_data(self, setup_database):
755760

756761
docs = loader.load()
757762

758-
deleted = db.delete(documents=[docs[0], docs[1]])
763+
deleted = db.delete(documents=docs)
759764

760765
assert deleted
761766

0 commit comments

Comments
 (0)