Daniele Varrazzo [Fri, 26 Jan 2024 09:47:31 +0000 (09:47 +0000)]
refactor: handle timeout in the connection generator, not the waiting function
The waiting function is supposed to be generic, the timeout is a policy
decision of the generator.
This change aligns the semantics of the `timeout` parameter of `wait_conn()`
to the one of the other wait functions: the timeout is actually an
interval. It will be renamed to clarify that in a followup commit.
Daniele Varrazzo [Wed, 24 Jan 2024 19:51:30 +0000 (19:51 +0000)]
fix: include timeout as part of the generators/wait conversation
So far, the wait functions would have shielded the generators from a
wait timeout. However this behaviour makes impossible to make a
generator interruptible.
Note that the `wait_c` generator was interruptible, but probably it
wasn't doing the right thing. In the `poll` branch, I understand that
the returned ready value, in case of timeout, would have been the same
of the input wait value, because of the input/output nature of the
pollfd struct; I haven't analyzed more deeply the select() case.
Michał Górny [Sat, 27 Jan 2024 14:28:34 +0000 (15:28 +0100)]
fix: add `libc.so` fallback for musl systems to the ctypes impl
Add a fallback to `libc.so` library name to fix loading the ctypes
implementation on musl systems. On musl, `find_library("c")` does
not work (the problem has been reported to CPython in 2014, and has not
been resolved yet), causing the module to fail on `assert libcname`.
Instead, add a fallback to using `libc.so` and let ctypes raise
an exception if such a library does not exist.
It was imported directly by typing_extensions to work around
https://github.com/microsoft/pyright/issues/4197
but the issue has been fixed in pyright 1.1.297, released almost one
year ago.
fix: perform multiple attemps if a host name resolve to multiple hosts
We now perform DNS resolution in Python both in the sync and async code.
Because the two code paths are now very similar, make sure they pass the
same tests.
Daniele Varrazzo [Fri, 29 Dec 2023 23:41:07 +0000 (00:41 +0100)]
fix(pool): use an exponential backoff to separate failing checks
This is a consistent behaviour with with the exponential backoff used in
reconnection attempts, and actually we could reuse the same object
implementing the backoff + jitter.
fix: define the Row TypeVar as defaulting to TupleRow
This allows to return `Self` uniformly from the `Connection.connect()` class
method, which in turns allows to subclass the connection without the
need of redefining the complex signature.
Daniele Varrazzo [Wed, 13 Dec 2023 13:20:49 +0000 (14:20 +0100)]
refactor: add compiled_default option to _get_params
Make it less awkward to come out with a 5432 when we really want a port
number (in name resolution) but still allow to leave it unspecified to
avoid mangling the conninfo.
nialov [Mon, 4 Dec 2023 17:33:46 +0000 (19:33 +0200)]
test: mark flaky ref count tests
All tests that have the 'gc' fixture are now marked with the refcount mark. The
reasoning is that they demonstrate flaky behaviour and disabling them in
certain CI is necessary to ensure reliable testing. See #692
Denis Laxalde [Thu, 30 Nov 2023 20:01:01 +0000 (21:01 +0100)]
test: let pytest show more info in summary
We add '-ra' to pytest options so as to get report about "(a)ll except
passed" tests. This is in particular useful to get the detailed message
about why some tests got skipped (especially useful in CI).
Daniele Varrazzo [Tue, 21 Nov 2023 08:49:24 +0000 (09:49 +0100)]
test: fix test failing to connect if env vars are cleaned
Add `dsn_env` fixture returning the `dsn` merged with the values in the
PG* env vars. This way the env can be cleaned but a working connection
string is still available.
Daniele Varrazzo [Mon, 13 Nov 2023 22:56:46 +0000 (23:56 +0100)]
chore: drop conninfo.resolve_hostaddr_async
The function is no more used internally and only exposed from the _dns
module with a warning. Its implementation is now an application of a few
internal functions exposed internally by the conninfo module. Move the
whole implementation into _dns.
Daniele Varrazzo [Sat, 11 Nov 2023 15:32:07 +0000 (15:32 +0000)]
chore: refresh 3rd party tests
- upgrade Python to 3.12
- test stable version of SQLAlchemy 2
- add missing SQLAlchemy test dependency
Testing Django with Python 3.12 not enabled yet as it requires pylibmc wheel
packages for Python 3.12 (https://github.com/lericson/pylibmc/issues/288).