mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 01:55:40 +00:00
fix and chore: refactor tests to minimize initializing DB connections
SUMMARY
The test suite was spinning up way too many database connections that what's
strictly needed and so the test suite was failing with[0]:
code: "53300", message: "sorry, too many clients already"
EXPERIMENTS
Tried sharing database connection pool across all tests with
async_once[0] but faced:
- IO errors
The connections were probably getting dropped in between tests
- actix Actor errors
The actor was probably not getting initialized before a
a reference to the async_once initialized app
context(crate::data::Data) is retrieved and used
FIX
crate::tests was spinning up an App context
instance(crate::data::Data) for most utility functions, which was
unnecessarily excessive.
Each test now creates an instance of the application context at the
beginning and shared a reference with all test utility functions. So
number of database connections/app context instance = number of unit
tests.
[0]: permanently fixes #22
[1]: https://docs.rs/async_once/latest/async_once/
This commit is contained in:
4
Makefile
4
Makefile
@@ -97,8 +97,8 @@ test: frontend-test frontend ## Run all available tests
|
||||
cd db/db-sqlx-postgres &&\
|
||||
DATABASE_URL=${POSTGRES_DATABASE_URL}\
|
||||
cargo test --no-fail-fast
|
||||
./scripts/tests.sh
|
||||
# cargo test --all-features --no-fail-fast
|
||||
cargo test --all-features --no-fail-fast
|
||||
# ./scripts/tests.sh
|
||||
|
||||
xml-test-coverage: migrate ## Generate code coverage report in XML format
|
||||
cargo tarpaulin -t 1200 --out Xml
|
||||
|
||||
Reference in New Issue
Block a user