News for hackers. Stuff that matters.
Re:Pg_branch: Pre-alpha Postgres extension brings Neon-like ... by Zanfa on Monday October 02, 2023 @04:20PM (#37743884)
A common pattern in Ruby-world is running each test case in a database transaction that is rolled back. A simple way to keep a clean slate in your test database.
Re:Pg_branch: Pre-alpha Postgres extension brings Neon-like ... by vb-8448 on Monday October 02, 2023 @04:44PM (#37744161)
It's also quite common in python and I guess in any other language. It's great for unittests, but not suitable for integration or end-to-end tests.
Re:Pg_branch: Pre-alpha Postgres extension brings Neon-like ... by sverhagen on Tuesday October 03, 2023 @01:49AM (#37748369)
Been there, done that, but please beware, this means that you're missing out on some nuanced behaviors that you would get if your subject under test would actually commit the transaction. I moved away from this entirely. A more-reliable setup is to let the test commit real transactions, and cleanup afterwards. You might be able to do that by calling "delete" on all repository instances, in the tearDown method of your tests. Or you could use something like Flyway to reset and reinitialize the database entirely before every test. That sounds expensive, and it certainly depends on the kind of project we're talking, but if this is a moderately-sized microservice, and you're running tests scoped to just that microservice, the setup shouldn't be too crazy, and this may actually run pretty smooth. (We run our database in a Testcontainers instance.)