Live data from Hacker News

Don't test with SQLite when you use Postgres in Production

michael.robellard.com

11–20 of 110 posts

Re: Don't test with SQLite when you use Postgres in Production

#11
post #7

I use MySQL in my system but the advice should be applicable to Postgres as well: keep your test database in a ramdisk. By moving my MySQL to ramdisk I got almost a tenfold improvement when running tests on a build server. Not so much (but also significant) improvement when running tests on my development machine.

Why do you think there was a difference between tests on a build server and on your development machine? Was it just a case of the build server being configured for performance?

Re: Don't test with SQLite when you use Postgres in Production

#14
This is one of those things that I would hope goes without saying, but obviously doesn't... Always test against what you expect to see in production. If you test against something else first (in this case mocking through an in-memory DB) to make the testing of other parts faster/easier then that is fine, but once those tests are done you still need to do a final full test against the real stack(s) you expect to see in production.

On the mocking thing: I thought the point of that was to completely avoid DB calls for speed when testing other logic layers, so even a fast in-memory DB isn't needed and anything (i.e. just some code that manufactures a response object) that produces a result set in the right format will do? In that case even using an in-memory DB is less efficient than the other option so is at best a "half optimisation". Am I missing a point here?

Re: Don't test with SQLite when you use Postgres in Production

#15
No, I will do this.

Because it's so much easier and it still lets me test 95% of my code. And the alternative is not testing at all because there is limited time for testing and setting up a proper database for this is so much more trouble.

The choices are not good test vs bad test. They are test-with-issues vs. no test.

(Obviously you have to do SOME testing with the real DB but this article is talking about unit tests (or related))

Re: Don't test with SQLite when you use Postgres in Production

#17
A few notes:

- All the concerns listed in this article are addressed by ORMs.

- SQLite supports CTE[1] (subqueries).

- It's safer to use the exact same setup in development and production, but it's slower for applications with many tests. It's a trade-off and that's all there is to say.

[1] http://stackoverflow.com/questions/21819183/how-to-use-ctes-...

Re: Don't test with SQLite when you use Postgres in Production

#18
post #7

I use MySQL in my system but the advice should be applicable to Postgres as well: keep your test database in a ramdisk. By moving my MySQL to ramdisk I got almost a tenfold improvement when running tests on a build server. Not so much (but also significant) improvement when running tests on my development machine.

Why do you think there was a difference between tests on a build server and on your development machine? Was it just a case of the build server being configured for performance?

I'm pretty sure that it's down to hard disk performance. I don't recall exact numbers but difference in IOPS between my development machine and a build server in the cloud (Azure) was greatly in favour of the former.

Re: Don't test with SQLite when you use Postgres in Production

#19
post #2

What about if you're using an ORM, wouldn't that fix the issues mentioned?

I have experienced plenty of issues with MySQL, many of which are fixed by changing the configuration. Using a different database doesn't make sense, unless you are in the very early stages.

Re: Don't test with SQLite when you use Postgres in Production

#20
If you're writing unit tests to test the business logic of your app, you shouldn't need a database at all. You should write your business logic so that it isn't dependent on a database, so you can really test the business logic and you don't have to mock the database.

If you're talking integration tests, then of course you should use an environment as close to production as possible.

Post reply on HN