How to rollback database transactions after test?

Hello , I am trying k6 for the first time and i want to load test Sign Up Api , i have an issue that i want to run the test on production and this will cause huge amount of dummy data added to production database , i wanted to ask if there is another way to do that without adding the data to the database or something i can write in the script to rollback database transactions after the tests are done?

Hi, welcome to the forum :slight_smile:

The ideal approach would be to use a production DB replica for tests of this kind that insert dummy data. Then you could drop the entire DB or restore from a snapshot. Alternatively, try to use some record that identifies the test, e.g. a test user email account, specific header, etc., so that you can identify all the records created for the test and remove them afterwards. This will depend a lot on your specific service and DB schema, so you’ll need to get creative.

Another option could be to register the created accounts externally, and then drop them in the teardown() function. See this PoC example that uses Redis/Webdis, and for relational DBs you might want to use the (experimental) xk6-sql extension.

So there’s a lot of options to consider, but no native support for this in k6. Good luck!


okk , Thank you so much for your help :pray: