db-pool is a thread-safe database pool for running database-tied integration tests in parallel with:

  • Easy setup
  • Proper isolation
  • Automatic creation, reuse, and cleanup
  • Async support

Description

Rather than simply providing a database connection pool that allows multiple connections to the same database, db-pool maintains a pool of separate isolated databases in order to allow running database-tied tests in parallel. It also handles the lifecycles of those databases: whenever you pick a database out of the pool, you can be sure that the database is clean and ready to be used, and that no other tests are connected to the database you are using in any one test.

Motivation

When running tests against a database-tied service, such as a web server, a test database is generally used. However, this comes with its own set of difficulties:

  1. The database has to be either (a) dropped and re-created or (b) cleaned before every test.
  2. Tests have to run serially in order to avoid cross-contamination.

This leads to several issues when running tests serially:

  • Test setup and teardown is now required.
  • Dropping and creating a database from scratch can be expensive.
  • Cleaning a database instead of dropping and re-creating one requires careful execution of dialect-specific statements.

When switching to parallel execution of tests, even more difficulties arise:

  • Creating and dropping a database for each test can be expensive.
  • Sharing temporary databases across tests requires:
    • isolating databases in concurrent use
    • cleaning each database before reuse by a subsequent test
    • restricting user privileges to prevent schema modification by rogue tests
    • dropping temporary databases before or after a test run to reduce clutter

db-pool takes care of all of these concerns while supporting multiple database types, backends, and connection pools.

Databases

  • MySQL (MariaDB)
  • PostgreSQL

Backends & Pools

Sync

BackendPoolFeature
diesel/mysqlr2d2diesel-mysql
diesel/postgresr2d2diesel-postgres
mysqlr2d2mysql
postgresr2d2postgres

Async

BackendPoolFeatures
diesel-async/mysqlbb8diesel-async-mysql, diesel-async-bb8
diesel-async/mysqlmobcdiesel-async-mysql, diesel-async-mobc
diesel-async/postgresbb8diesel-async-postgres, diesel-async-bb8
diesel-async/postgresmobcdiesel-async-postgres, diesel-async-mobc
sea-orm/sqlx-mysqlsqlxsea-orm-mysql
sea-orm/sqlx-postgressqlxsea-orm-postgres
sqlx/mysqlsqlxsqlx-mysql
sqlx/postgressqlxsqlx-postgres
tokio-postgresbb8tokio-postgres, tokio-postgres-bb8
tokio-postgresmobctokio-postgres, tokio-postgres-mobc