Skip to content

Commit d8aafee

Browse files
authored
Use blockbuster to detect blocking calls (#324)
1 parent 5d80307 commit d8aafee

File tree

8 files changed

+50
-14
lines changed

8 files changed

+50
-14
lines changed

astrapy/data/database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3226,7 +3226,7 @@ async def _list_tables_ctx(
32263226
driver_commander = self._get_driver_commander(keyspace=keyspace)
32273227
lt_payload = {"listTables": {"options": {"explain": True}}}
32283228
logger.info("listTables")
3229-
lt_response = driver_commander.request(
3229+
lt_response = await driver_commander.async_request(
32303230
payload=lt_payload,
32313231
timeout_context=timeout_context,
32323232
)

poetry.lock

Lines changed: 26 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pytest-httpserver = "~1.0.8"
5050
testcontainers = "~3.7.1"
5151
ruff = "^0.6.8"
5252
types-toml = "^0.10.8.7"
53+
blockbuster = "~1.5.5"
5354

5455
[build-system]
5556
requires = ["poetry-core>=1.0.0"]

tests/admin/integration/test_admin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from __future__ import annotations
1616

17+
import asyncio
1718
import time
1819
from typing import Any, Awaitable, Callable
1920

@@ -72,7 +73,7 @@ async def await_until_true(
7273
while not (await acondition()):
7374
if time.time() - ini_time > max_seconds:
7475
raise ValueError("Timed out on condition.")
75-
time.sleep(poll_interval)
76+
await asyncio.sleep(poll_interval)
7677

7778

7879
@pytest.mark.skipif(not IS_ASTRA_DB, reason="Not supported outside of Astra DB")

tests/base/integration/collections/test_collection_ddl_async.py

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

1515
from __future__ import annotations
1616

17-
import time
17+
import asyncio
1818

1919
import pytest
2020

@@ -146,7 +146,7 @@ async def test_collection_default_id_type_async(
146146
assert isinstance(doc["_id"], UUID)
147147
await acol.drop()
148148

149-
time.sleep(2)
149+
await asyncio.sleep(2)
150150
acol = await async_database.create_collection(
151151
ID_TEST_COLLECTION_NAME_ROOT + DefaultIdType.UUIDV6,
152152
definition=CollectionDefinition(
@@ -168,7 +168,7 @@ async def test_collection_default_id_type_async(
168168
assert doc["_id"].version == 6
169169
await acol.drop()
170170

171-
time.sleep(2)
171+
await asyncio.sleep(2)
172172
acol = await async_database.create_collection(
173173
ID_TEST_COLLECTION_NAME_ROOT + DefaultIdType.UUIDV7,
174174
definition=CollectionDefinition(
@@ -190,7 +190,7 @@ async def test_collection_default_id_type_async(
190190
assert doc["_id"].version == 7
191191
await acol.drop()
192192

193-
time.sleep(2)
193+
await asyncio.sleep(2)
194194
acol = await async_database.create_collection(
195195
ID_TEST_COLLECTION_NAME_ROOT + DefaultIdType.DEFAULT,
196196
definition=CollectionDefinition(
@@ -205,7 +205,7 @@ async def test_collection_default_id_type_async(
205205
assert acol_options.default_id.default_id_type == DefaultIdType.DEFAULT
206206
await acol.drop()
207207

208-
time.sleep(2)
208+
await asyncio.sleep(2)
209209
acol = await async_database.create_collection(
210210
ID_TEST_COLLECTION_NAME_ROOT + DefaultIdType.OBJECTID,
211211
definition=CollectionDefinition(
@@ -429,7 +429,7 @@ async def test_tokenless_client_async(
429429
@pytest.mark.describe(
430430
"test database-from-admin default keyspace per environment, async"
431431
)
432-
async def test_database_from_admin_default_keyspace_per_environment_async(
432+
def test_async_database_from_admin_default_keyspace_per_environment(
433433
self,
434434
data_api_credentials_kwargs: DataAPICredentials,
435435
data_api_credentials_info: DataAPICredentialsInfo,
@@ -448,7 +448,7 @@ async def test_database_from_admin_default_keyspace_per_environment_async(
448448
@pytest.mark.describe(
449449
"test database-from-astradbadmin default keyspace per environment, async"
450450
)
451-
async def test_database_from_astradbadmin_default_keyspace_per_environment_async(
451+
def test_async_database_from_astradbadmin_default_keyspace_per_environment(
452452
self,
453453
data_api_credentials_kwargs: DataAPICredentials,
454454
data_api_credentials_info: DataAPICredentialsInfo,

tests/base/integration/collections/test_collection_timeout_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ async def test_cursor_overalltimeout_exceptions_async(
8080
acol = async_empty_collection
8181
await acol.insert_many([{"a": 1}] * 1000)
8282

83-
await acol.distinct("a", timeout_ms=20000)
83+
await acol.distinct("a", timeout_ms=60000)
8484
with pytest.raises(DataAPITimeoutException):
8585
await acol.distinct("a", timeout_ms=1)
8686

87-
await acol.distinct("a", timeout_ms=20000)
87+
await acol.distinct("a", timeout_ms=60000)
8888
with pytest.raises(DataAPITimeoutException):
8989
await acol.distinct("a", timeout_ms=1)
9090

tests/base/integration/misc/test_vectorize_ops_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def test_collection_methods_vectorize_async(
2929
async_database: AsyncDatabase,
3030
) -> None:
3131
database_admin = async_database.get_database_admin()
32-
ep_result = database_admin.find_embedding_providers()
32+
ep_result = await database_admin.async_find_embedding_providers()
3333

3434
assert isinstance(ep_result, FindEmbeddingProvidersResult)
3535

tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020

2121
import functools
2222
import warnings
23+
from collections.abc import Iterator
2324
from typing import Any, Awaitable, Callable, Iterable, TypedDict
2425

2526
import pytest
27+
from blockbuster import BlockBuster, blockbuster_ctx
2628
from deprecation import UnsupportedWarning
2729

2830
from astrapy import AsyncDatabase, DataAPIClient, Database
@@ -51,6 +53,14 @@
5153
)
5254

5355

56+
@pytest.fixture(autouse=True)
57+
def blockbuster() -> Iterator[BlockBuster]:
58+
with blockbuster_ctx() as bb:
59+
# TODO: follow discussion in https://github.com/encode/httpx/discussions/3456
60+
bb.functions["os.stat"].can_block_in("httpx/_client.py", "_init_transport")
61+
yield bb
62+
63+
5464
class DataAPICredentials(TypedDict):
5565
token: str | TokenProvider
5666
api_endpoint: str

0 commit comments

Comments
 (0)