10× faster database tests with Docker ↦
Testing code that talks to the database can be slow. Fakes are fast but unrealistic. What to do? With a little help from Docker, you can write tests that run fast, use the real database, are easy to write and run.
I tried Itamar’s technique on changelog.com’s test suite and the 679 tests complete in ~17 seconds. The same tests run directly against Postgres complete in ~12 seconds.
A net loss for me, but that may have something to do with how Docker for Mac works? I’d love to hear other people’s experiences.
Discussion
Sign in or Join to comment or subscribe
Itamar Turner-Trauring
Helping Python software teams ship features faster.
2019-02-27T16:52:17Z ago
Apparently Docker for Mac does add a lot of filesystem I/O overhead, yeah.
The solution might be RAM disk, but the tmpfs method won’t work on Mac. You can use native Mac RAM disks, though, as documented here: https://devops.stackexchange.com/questions/4012/does-docker-on-macos-support-tmpfs
Can you try that and see if it speeds thing up?
Jerod Santo
Bennington, Nebraska
Jerod co-hosts The Changelog, crashes JS Party & takes out the trash (his old code) once in awhile.
2019-02-27T19:28:38Z ago
Gave it a shot and sadly no noticeable difference ¯\(ツ)/¯
Itamar Turner-Trauring
Helping Python software teams ship features faster.
2019-02-27T19:31:06Z ago
Sorry it didn’t work for you :( On the plus side, 17 seconds isn’t that bad.