Denis Laxalde [Sun, 5 Feb 2023 17:40:16 +0000 (18:40 +0100)]
test: use Windows asyncio policy in "non-asyncio" pool tests
In commit b6cc8343159fc0a27365e09a3beef06433f3f1b5, we drop the global
asyncio.set_event_loop_policy() for Windows in conftest.py, replacing it
with asyncio_options to be used by the anyio test runner. However, test
cases in test_pool_async_noasyncio.py are not "async def" so they would
not use that anyio runner (nor did they use pytest-asyncio's runner
before); but they need the event loop policy for Windows still.
Accordingly, we configure the loop from "anyio_backend_options" in
asyncio_run() fixture.
Denis Laxalde [Wed, 17 Aug 2022 13:59:31 +0000 (15:59 +0200)]
test: use anyio instead of pytest-asyncio
This is in preparation for adding support for other async libraries,
through anyio. AnyIO pytest plugin is used in replacement for
pytest-asyncio:
- either the pytest.mark.asyncio is replaced by pytest.mark.anyio, or,
- we rely on the 'anyio_backend' fixture that is pulled in 'aconn_cls'
fixture (and hence 'aconn') providing automatic detection for test
functions using it.
The 'anyio_backend' fixture is parametrized to only use asyncio and
selects the event loop policy we need on Windows platform as previously
done in pytest_sessionstart(), but only for Python version 3.8 or
higher.
This fixture is defined in main conftest.py, as well as in
pool/conftest.py since we'll change the former to support more async
backend while keeping the later asyncio-only for now.
Function test_concurrency_async.py::test_ctrl_c is no longer 'async'
because its code does not directly use asyncio (it's done through a
subprocess); but the 'async def' was needed before in order for
pytest-asyncio to run it since the test module had a global
pytest.mark.asyncio (and we were using the "auto" mode).
Denis Laxalde [Mon, 9 Jan 2023 20:26:46 +0000 (21:26 +0100)]
refactor: merge BaseCursor's _set_results() and _set_results_from_pipeline()
Per refactoring of previous commits, these are similar: the only
difference is the use of "first_batch" flag in the execute() branch when
not in pipeline mode, but in that case since there is actually only one
"batch", the behavior is actually preserved.
Since _set_results_from_pipeline() previously included a call to
_check_results() but _set_results() does not, that is reported in caller
(BasePipeline._process_results()).
Ran Benita [Tue, 24 Jan 2023 20:59:55 +0000 (22:59 +0200)]
refactor(pool): make constructor configuration parameters type-safe
Previously, arguments to ConnectionPool and friends would be forwarded
using `**kwargs` to `BasePool`. This is however not type-safe, and
prevents code editors from auto-completing the parameters.
Drop the `**kwargs`, duplicate the parameters instead.
Denis Laxalde [Sat, 7 Jan 2023 15:01:36 +0000 (16:01 +0100)]
fix: set rowcount to the first result in executemany(..., returning=True)
Previously, _rowcount was unconditionally set to the overall number of
rows of all queries in executemany() and then reset only upon the first
call to nextset(). In the returning=True case, this lead the rowcount
attribute to be wrong for the first result (i.e. it didn't match the
number of rows that would be returned by .fetchall(), as can be seen in
updated tests).
Now we only set _rowcount to the cumulated number of rows of executed
queries *if* executemany() is not returning (so the value is still
useful, e.g., in to check the number of INSERTed rows):
>>> cur.executemany("INSERT INTO t(r) VALUES (%s)", [(1,), (2,)])
>>> cur.rowcount
2 # number of inserted rows
>>> cur.nextset()
>>> cur.executemany("INSERT INTO t(r) VALUES (%s) RETURNING r", [(1,), (2,)], returning=True)
>>> cur.rowcount
1 # number of rows in the first result set
>>> cur.fetchall()
[(1,)]
>>> cur.nextset()
True
>>> cur.rowcount
1
>>> cur.fetchall()
[(2,)]
>>> cur.nextset()
Besides, the code for processing results from executemany() in
_executemany_gen_no_pipeline() is now similar to that of
_set_results_from_pipeline().
Denis Laxalde [Sun, 8 Jan 2023 14:48:38 +0000 (15:48 +0100)]
refactor: drop superfluous _rowcount reset
In BaseCursor._set_results_from_pipeline() we were resetting _rowcount
if negative. This is superfluous as this code is reached when coming
from _executemany_gen_pipeline() in which we already do
'self._rowcount = 0' early on.
Daniele Varrazzo [Tue, 20 Dec 2022 20:19:23 +0000 (20:19 +0000)]
ci: configure the database to run two-phase-commit tests
We can't use the Github Actions PostgreSQL service because it doesn't
seem possible to configure the server for stored transactions:
- the service yaml definition doesn't take args to pass to run
- we can't overwrite the entry point with a script of ours because the
service starts before actions/checkout
- the postgres image doesn't allow to pass extra parameters to the
server via an env var