Rollback of startup functions

19 views
Skip to first unread message

Stefan Chipilov

unread,
Jan 9, 2022, 9:12:15 AM1/9/22
to pgTAP Users
Is there a way to automatically rollback any data changes from startup* functions (similar to how changes from setup* functions are automatically rolledback)?

My specific use case is that I want to "clean" all data from my dev db when tests start but, I don't want to erase all my dev data every time I run the tests.

Currently, I workaround this by simply cleaning in a setup* functions. My main concern is that as the number of tests grows, runs will become slower and slower since each test will clean the entire db (this of course, has the benefit of ensuring that each test is independent from others, but that's a different consideration).

Regards,
Stefan

David E. Wheeler

unread,
Jan 9, 2022, 10:12:30 AM1/9/22
to Stefan Chipilov, pgTAP Users
On Jan 9, 2022, at 09:12, Stefan Chipilov <chip...@gmail.com> wrote:
>
> Is there a way to automatically rollback any data changes from startup* functions (similar to how changes from setup* functions are automatically rolledback)?

No. A startup function is designed to set things up for all your tests, not individual tests.

> Currently, I workaround this by simply cleaning in a setup* functions. My main concern is that as the number of tests grows, runs will become slower and slower since each test will clean the entire db (this of course, has the benefit of ensuring that each test is independent from others, but that's a different consideration).

Yes, that is the way to do it. The alternative is to separate the functions by naming them differently. So if only 4 out of 10 of your test functions need the startup data, prefix those four and their startup function with some text to separate them from the others. Something like heavy_startup(), heavy_setup(), heavy_test_foo(), heavy_teardown(), heavy_shutdown(). Then run them from a separate script with

SELET * FROM runtests('testschema', ‘^heavy_');

Best,

David

Reply all
Reply to author
Forward
0 new messages