Skip to content

Commit 789e655

Browse files
committed
Fix database test concurrency issue
1 parent c92734d commit 789e655

4 files changed

Lines changed: 88 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "terminusdb-client"
3-
version = "12.0.3"
3+
version = "12.0.5"
44
description = "Python client for Terminus DB"
55
authors = ["TerminusDB group"]
66
license = "Apache Software License"

terminusdb_client/tests/integration_tests/conftest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ def docker_url(pytestconfig):
145145
"""
146146
# Check if a server is already running (port 6363)
147147
if is_local_server_running():
148-
print(
149-
"\n✓ Using existing TerminusDB server at http://127.0.0.1:6363"
150-
)
148+
print("\n✓ Using existing TerminusDB server at http://127.0.0.1:6363")
151149
yield "http://127.0.0.1:6363"
152150
return # Don't clean up - server was already running
153151

terminusdb_client/tests/integration_tests/test_client.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,65 @@
1212

1313
test_user_agent = "terminusdb-client-python-tests"
1414

15+
_CLIENT_TEST_DBS = ["test_diff_ops"]
16+
_CLIENT_TEST_ORGS = ["testOrg235091"]
17+
18+
19+
@pytest.fixture(scope="module", autouse=True)
20+
def cleanup_client_resources(docker_url):
21+
"""Delete stale databases and organizations before the module and clean up after."""
22+
client = Client(docker_url, user_agent=test_user_agent)
23+
client.connect()
24+
25+
def _cleanup():
26+
for db in _CLIENT_TEST_DBS:
27+
try:
28+
client.delete_database(db)
29+
except Exception:
30+
pass
31+
for org in _CLIENT_TEST_ORGS:
32+
# Ensure admin has access so we can list and delete databases
33+
try:
34+
client.change_capabilities(
35+
{
36+
"operation": "grant",
37+
"scope": f"Organization/{org}",
38+
"user": "User/admin",
39+
"roles": ["Role/admin"],
40+
}
41+
)
42+
except Exception:
43+
pass
44+
try:
45+
dbs = client.get_organization_user_databases(org=org, username="admin")
46+
for db in dbs:
47+
try:
48+
client.delete_database(db["name"], team=org)
49+
except Exception:
50+
pass
51+
except Exception:
52+
pass
53+
# Revoke capabilities before deleting org
54+
try:
55+
client.change_capabilities(
56+
{
57+
"operation": "revoke",
58+
"scope": f"Organization/{org}",
59+
"user": "User/admin",
60+
"roles": ["Role/admin"],
61+
}
62+
)
63+
except Exception:
64+
pass
65+
try:
66+
client.delete_organization(org)
67+
except Exception:
68+
pass
69+
70+
_cleanup()
71+
yield
72+
_cleanup()
73+
1574

1675
def test_not_ok():
1776
client = Client("http://localhost:6363")

terminusdb_client/tests/integration_tests/test_schema.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,33 @@
88

99
test_user_agent = "terminusdb-client-python-tests"
1010

11+
_SCHEMA_TEST_DBS = [
12+
"test_docapi",
13+
"test_docapi2",
14+
"test_datetime",
15+
"test_compress_data",
16+
"test_repeated_load",
17+
"test_repeated_load_fails",
18+
]
19+
20+
21+
@pytest.fixture(scope="module", autouse=True)
22+
def cleanup_schema_databases(docker_url):
23+
"""Delete stale databases before the module and clean up after."""
24+
client = Client(docker_url, user_agent=test_user_agent)
25+
client.connect()
26+
for db in _SCHEMA_TEST_DBS:
27+
try:
28+
client.delete_database(db)
29+
except Exception:
30+
pass
31+
yield
32+
for db in _SCHEMA_TEST_DBS:
33+
try:
34+
client.delete_database(db)
35+
except Exception:
36+
pass
37+
1138

1239
def test_create_schema(docker_url, test_schema):
1340
my_schema = test_schema

0 commit comments

Comments
 (0)