3 ms·
We're using PostgreSQL teams to create a database from a template for every integration test worker (Jest). This way every worker works on their own database.
by KingOfCoders 6y ago
We're using PostgreSQL teams to create a database from a template for every integration test worker (Jest).
This way every worker works on their own database. The speedup was 5x-7x as tests are now running in parallel.
- jayd16 6y agoDo you store test data in the template? My team uses a migration framework (in our case Flyway) such that we can easily create completely fresh DBs on a factory fresh(+ user roles) instance of Postgres. We do this for our testing as well. This means the schema tools are always tested as well. Is there a benefit to using templates? They're faster perhaps?
- flavor8 6y agoWe use flyway to create a template. Then each test that mutates the DB automatically invokes a cleanup routine which recreates the test DB from the template. You get into hot water around the connection pooling, but it's much, much faster than refreshing using flyway.
- tln 6y agoI'm using templates as well for the speedup in testing. We build a postgresql docker image with the migrations + seed data, then create a few databases for parallel testing. When migration or seed files have changed, rules rebuild the image. That way the price of migration (about 2 minutes for our Django app) isn't paid on every test run. Creating a DB from template is 2 seconds.
- KingOfCoders 6y agoFor 10 workers it takes <0.5 seconds to create 10 databases from the template. Test data is created from within tests.
- Xeronate 6y agoI’ve seen two people mention this for integration tests and that sounds great, but how do you handle system tests? As an example of the difference, my team would use an integration to test a repository class individually and a system test to check everything from the top level api endpoint and down. I think the top level thing is important because it makes sure we are getting the right connection string from our database provider and what not.
- KingOfCoders 6y agoWhere do you see problems with system tests? Shouldn't they work the same with one database per worker/thread?