DEV Community

Nenad Stojanovikj
Nenad Stojanovikj

Posted on

Speed up your integration tests in one line

If you are using Docker to run your integration tests, and they use a real database (MySQL, PostgreSQL, MongoDB, etc), you are in luck. By simply mounting the directory of the database files on tmpfs in the containers, you will be able to reduce the execution time by a substantial amount[1]. In my case, I reduced the tests from 17 minutes execution time, to just 4 minutes.

This tmpfs flag is supported also in docker-compose.

Example docker-compose file for MySQL, PostgreSQL and MongoDB:

version: '3'
services:
  mongo_db:
    image: mongo:3.4.6
    ports:
      - "27017"
    tmpfs:
      - /var/lib/mongodb

  mysql_db:
    image: mysql:5.6.34
    ports:
      - "3306"
    tmpfs:
      - /var/lib/mysql

  postgres_db:
    image: postgres:11
    ports:
      - "5432"
    tmpfs:
      - /var/lib/postgresql/data

To launch a container with a tmpfs from the CLI, use the --tmpfs flat, just like it's described in the docs:

$ docker run -d -it --name tmptest --tmpfs /app nginx:latest

[1]: This will vary depending on the usage of the database during the test runs. If you don't utilize the database a lot, you might not even notice any improvements.

Top comments (0)