pgtap icon indicating copy to clipboard operation
pgtap copied to clipboard

Parallel testing with fixtures

Open dvasdekis opened this issue 3 years ago • 3 comments

Hey folks!

What would be the right way to test in parallel with setup fixtures?

I am thinking about something that will:

  1. Run my test in a separate isolated database using CREATE DATABASE my_new_database TEMPLATE my_old_database; (as a substitute for BEGIN; ROLLBACK; capability which would be unavailable across multiple transactions)
  2. Execute runtests() using the new database, with each stage run in parallel (with connections = function count for that stage)
  3. Emit the test output
  4. Drop the newly created database

Am I missing anything here? This would be a pretty simple job to whip up in Python, and I'm happy to do it. I'm just wondering why this doesn't yet exist/isn't built into pg_prove already (which is phenomenal as-is! don't get me wrong!)

Thoughts?

dvasdekis avatar Mar 09 '21 00:03 dvasdekis

I guess the -j flag on pg_prove doesn't work for runtests() tests?

theory avatar Mar 11 '21 02:03 theory

To be honest I haven't tried it, but don't you say that yourself in the docs? https://pgtap.org/documentation.html#runtests - ("Note that all tests executed by runtests() are run within a single transaction...")

On Thu, 11 Mar 2021, 12:29 David E. Wheeler, [email protected] wrote:

I guess the -j flag on pg_prove doesn't work for runtests() tests?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/theory/pgtap/issues/267#issuecomment-796384727, or unsubscribe https://github.com/notifications/unsubscribe-auth/AETC4JOQOFSR3T2KBL422QDTDAMF7ANCNFSM4Y2NUZTQ .

dvasdekis avatar Mar 11 '21 05:03 dvasdekis

Yes, you're right, that's what the docs say. I think the simplest way to get parallelism is to create multiple test scripts, each of which runs a discrete subset of the tests, then use pg_prove -j to run them all. Would be interesting to think about how one might do it in pg_prove itself, but I don't think it can be done in pgTAP. Have you tried your approach with Python? Curious how it turned out.

theory avatar Apr 17 '22 21:04 theory