I am trying to migrate my unit tests from H2 to Postgresql.
Currently, H2 gives me an in-memory schema such that each connection maps to a unique schema, creates the tables, runs the test, and drops the schema. The schema creation and destruction is handled automatically by H2.
The unit tests run concurrently.
What is the best way to do this in Postgresql? Specifically,
- How do I get a unique schema per connection?
- Should the test framework generate unique names or is there a built-in mechanism for doing this?
- How do I ensure that the schema is dropped when the connection is dropped?
- I don't want to end up with dangling schemas when unit tests get killed.
- What approach will yield the highest performance?
- I need to create/drop tens of schemas per second.
UPDATE: I found a related answer here but it fails to drop schemas in case the process running the unit tests gets killed.