Skip to content

test: reduce acquire_timeout_secs in test_database_pool_failure to speed up test suite 16x #281

Open

Description

@ZhuchkaTriplesix

Where:
tests/test_database_pool.py:11 (test_database_pool_failure)

Currently:
test_database_pool_failure attempts to connect to a non-existent database port without specifying a timeout:

await app.setup_database("postgresql://foo:bar@127.0.0.1:12345/baz")

Because setup_database defaults to acquire_timeout_secs = 30.0, sqlx waits for the entire 30 seconds before failing.
Out of the 31.94-second total pytest runtime, this single test consumes 30.00 seconds (94%), while all other 206 tests complete in 1.94 seconds!

Fix direction:
Pass an explicit short timeout in the test:

await app.setup_database("postgresql://foo:bar@127.0.0.1:12345/baz", acquire_timeout_secs=0.5)

This will drop the test duration from 30.00s to 0.50s, accelerating total test suite execution across local runs and CI matrix jobs by 16x.

Activity

  1. CodeByPeace commented on Oct 18, 2026

    @CodeByPeace

    I checked this before trying the fix, and acquire_timeout_secs isn’t accepted by setup_database. In src/lib.rs the signature is #[pyo3(signature = (url, max_connections=10))], and “timeout” doesn’t appear anywhere in src. So acquire_timeout_secs=0.5 in the test would raise a TypeError.

    oxyroute/_oxyroute.pyi lists min_connections, acquire_timeout_secs, idle_timeout_secs and max_lifetime_secs, but the Rust side has none of them, so the stub is ahead of the code.

    To speed the test up, the parameter would have to be added in Rust first (sqlx has PgPoolOptions::acquire_timeout).
    Do you want that added, or should the stub be corrected instead? I can take either one.

  2. ZhuchkaTriplesix commented on Oct 18, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Hey @CodeByPeace! Great research and spot-on observation, you're 100% right.

    We definitely want to implement these parameters in Rust rather than downgrading the .pyi stub! We actually just opened #290 to track full connection pool tuning for setup_database.

    We'd love to have your PR for this! The plan is:

    1. Wire min_connections, max_connections, acquire_timeout_secs, idle_timeout_secs, and max_lifetime_secs into sqlx::postgres::PgPoolOptions in src/lib.rs and forward them in oxyroute/app.py.
    2. Use acquire_timeout_secs=0.5 in tests/test_database_pool.py:11 to speed up the test suite 16x.

    Please make sure to target the integration branch dev for your PR (see docs/development-workflow.md).

    Thanks again for the thorough catch, go right ahead!

  3. CodeByPeace commented on Oct 18, 2026

    @CodeByPeace

    Thanks, I’ll take it.
    I’ll branch from dev, wire the five options into PgPoolOptions and app.py, and use acquire_timeout_secs=0.5 in the test.
    I’ll also reject negative or non-finite values, since Duration::from_secs_f64 panics on them.

  4. CodeByPeace commented on Oct 18, 2026

    @CodeByPeace

    Opened PR #292 for this. It wires all four options into PgPoolOptions and uses acquire_timeout_secs=0.5 in the pool test, which now runs in about 0.5s instead of 30s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions