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/
SUMMARY
The test suite messy and inefficient in every imaginable way. It
creates a DB connection pool for every unit test and Postgres failed
with the following error:
code: "53300", message: "sorry, too many clients already
This hotfix runs tests via scripts/tests.sh, which executes one test
at a time.
Ideally, the connection pool must be shared across the whole test
suite but this requires a major refactor of the test suite and even
the app code. A refactor towards this is in progress in the
`db-abstract` branch, which I hope to complete within this week.
fixes#22