Skip to content

Commit c28bbc8

Browse files
Migrate fork-guard tests to pid-cache patch and apply asyncio mark per-method
Two cycle-21 follow-ups in the dbapi tests: - Fork-guard tests (sync + async) patched ``dqlitedbapi.connection.os.getpid`` and ``dqlitedbapi.aio.connection.os.getpid``. Cycle 21 moved every hot-path pid check to read ``dqliteclient.connection._current_pid`` via the register_at_fork-refreshed module cache. The ``patch("...os.getpid", ...)`` patches were dead code; the tests passed only because they also mutated ``_creator_pid`` directly. Migrate to patching the cache. - ``TestAsyncTpcStubs`` carried a class-level ``@pytest.mark.asyncio`` decorator but ``test_xid`` is a synchronous method. Under pytest-asyncio's strict mode this can fail collection. Move the mark from the class to each async method individually, matching the sibling ``TestAsyncStdlibParityStubs`` class's per-method pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3108289 commit c28bbc8

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

tests/aio/test_async_connection_fork_guard.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def test_async_connection_used_after_fork_raises_interface_error() -> None
3535
conn._creator_pid = fake_parent_pid
3636

3737
with (
38-
patch("dqlitedbapi.aio.connection.os.getpid", return_value=fake_parent_pid + 1),
38+
patch("dqliteclient.connection._current_pid", fake_parent_pid + 1),
3939
pytest.raises(InterfaceError, match="fork"),
4040
):
4141
conn._ensure_locks()
@@ -56,7 +56,7 @@ def test_force_close_transport_after_fork_short_circuits() -> None:
5656
fake_parent_pid = conn._creator_pid + 1
5757
conn._creator_pid = fake_parent_pid
5858

59-
with patch("dqlitedbapi.aio.connection.os.getpid", return_value=fake_parent_pid + 1):
59+
with patch("dqliteclient.connection._current_pid", fake_parent_pid + 1):
6060
conn.force_close_transport()
6161

6262
writer.close.assert_not_called()
@@ -82,7 +82,7 @@ async def test_async_connection_close_after_fork_short_circuits() -> None:
8282
fake_parent_pid = conn._creator_pid + 1
8383
conn._creator_pid = fake_parent_pid
8484

85-
with patch("dqlitedbapi.aio.connection.os.getpid", return_value=fake_parent_pid + 1):
85+
with patch("dqliteclient.connection._current_pid", fake_parent_pid + 1):
8686
await conn.close()
8787

8888
inner.close.assert_not_called()

tests/test_connection_after_fork_raises.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_dbapi_close_after_fork_scrubs_cursors() -> None:
9595
conn._creator_pid = fake_parent_pid
9696

9797
try:
98-
with patch("dqlitedbapi.connection.os.getpid", return_value=fake_parent_pid + 1):
98+
with patch("dqliteclient.connection._current_pid", fake_parent_pid + 1):
9999
conn.close()
100100

101101
assert cursor._closed is True

tests/test_unsupported_method_stubs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,28 @@ def test_create_window_function(self, conn: dqlitedbapi.Connection) -> None:
103103
conn.create_window_function("name", 0, object)
104104

105105

106-
@pytest.mark.asyncio
107106
class TestAsyncTpcStubs:
107+
@pytest.mark.asyncio
108108
async def test_tpc_begin(self, aconn: AsyncConnection) -> None:
109109
with pytest.raises(NotSupportedError):
110110
await aconn.tpc_begin(object())
111111

112+
@pytest.mark.asyncio
112113
async def test_tpc_prepare(self, aconn: AsyncConnection) -> None:
113114
with pytest.raises(NotSupportedError):
114115
await aconn.tpc_prepare()
115116

117+
@pytest.mark.asyncio
116118
async def test_tpc_commit(self, aconn: AsyncConnection) -> None:
117119
with pytest.raises(NotSupportedError):
118120
await aconn.tpc_commit()
119121

122+
@pytest.mark.asyncio
120123
async def test_tpc_rollback(self, aconn: AsyncConnection) -> None:
121124
with pytest.raises(NotSupportedError):
122125
await aconn.tpc_rollback()
123126

127+
@pytest.mark.asyncio
124128
async def test_tpc_recover(self, aconn: AsyncConnection) -> None:
125129
with pytest.raises(NotSupportedError):
126130
await aconn.tpc_recover()

0 commit comments

Comments
 (0)