Skip to content

Test binaries abort when a name filter matches tests that construct a DbHandler (CONFIG parses the test argv) #89

Description

@erans

Found while working on #80. Pre-existing on main, independent of that change.

Reproduce

cargo test --lib sql_injection

Observed

error: unexpected argument '--nocapture' found

  tip: a similar argument exists: '--no-tcp'

Usage: <test-binary> --no-tcp
error: test failed

or, with a bare filter, the process exits non-zero before running the matched tests.

Cause

config::CONFIG is a lazy_static whose initializer calls Config::load()Config::parse() (src/config.rs). In a test binary, argv belongs to the libtest harness, not to pgsqlite, so clap sees --nocapture or a filter string, rejects it, and calls process::exit.

Anything that touches CONFIG in a test binary triggers this. db_handler::tests::test_sql_injection_patterns constructs a DbHandler, which initializes lazy statics that dereference CONFIGsrc/session/state.rs:15, src/cache/statement_pool.rs:35, src/cache/execution.rs:130, src/cache/result_cache.rs:246.

Impact

  • cargo test -- --nocapture is unusable for any test that reaches CONFIG, which is most integration tests, since session creation initializes those caches. This makes debugging test failures materially harder.
  • Any cargo test --lib <filter> whose filter matches those db_handler tests aborts rather than running.
  • It is a trap for new code: Add --hide-internal-tables flag to hide __pgsqlite_* tables from client sqlite_master queries (#80) #85 had to design around it explicitly, gating its feature flag behind a plain AtomicBool set from main rather than reading CONFIG at the call sites, purely so the feature would be testable.

Possible fixes

  • Have Config::load() fall back to Config::parse_from(["pgsqlite"]) (defaults only) when running under a test harness — detectable via cfg!(test) for lib tests, though not for integration test binaries.
  • Or use try_parse() and fall back to defaults on error instead of exiting, at least when argv[0] is not the pgsqlite binary.
  • Or make the tests that construct a DbHandler inject a Config rather than relying on the global.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions