5 ms·
I write applications that use Postgres, and don't use Docker for testing. I just create a database based on the name of the test case, delete it, create it, ex
by jrockway 5y ago
I write applications that use Postgres, and don't use Docker for testing. I just create a database based on the name of the test case, delete it, create it, explode the schema in there, and run the tests. The reason is because I don't want to pay Postgres' startup costs every time I run the tests. Tests are run thousands of times a day, while you're in the mindset to rapidly iterate. Any delay is unacceptable.
At some point, migrations were taking too long, so I just started caching the database schema. I have a go generate thingie that creates a fresh database, applies all the migrations, and dumps the schema to a file that gets checked in with the code. (CI checks that the migrations actually result in the database state that's checked in. Yes, there is something that regexes out the hostname from the sql file, since Postgres dumps that in there by default and that results in spurious diffs.)
I have learned that people often put up with really sub-optimal developer workflows. My test is that you should be able to add "print hello world" to the top of your main function, and see that printed on your screen in less than 5 seconds. (Yes, even if your application is complicated. I have a hacked up copy of K8s that starts that quickly, so that you can write an app that deeply integrates with K8s and not have to reuse a cluster between tests, or pay a long cluster creation cost. All obstacles must be removed!) If it takes longer than that, you are just throwing your developer's salaries into the toilet. (If it takes 6 seconds, you open up HN, and there's an hour gone!)