1

I am using Karate + Gatling to test one async backend system.

User in a test

  1. Files a ticket with the backend
  2. Waits for the ticket to start processing (max 10 tickets are processing in parallel, rest of them wait in queue)
  3. When processing starts, wait for it to finish (~ 1min)
  4. When processing finishes, check result and end test

The problem is that if the test fails in steps 2 or 3 (timeout on GET request, random traffic fail), the ticket still stays on the backend and will take time to process, interfering with the following users.

I would like to delete the ticket manually if the test fails on steps 2 or 3. Is that possible with gatling? Is there some way that I could execute some after hook if a user ends in failure? Can I know where the test failed?

Stéphane LANDELLE
  • 6,076
  • 2
  • 10
  • 12
Milan Smolík
  • 399
  • 2
  • 12

1 Answers1

1

This is an area where I suggest you do some research and contribute your findings back to the community.

Karate has a concept of hooks: https://stackoverflow.com/a/59080128/143475

So if you implement the RuntimeHook you should have full-control over detecting errors and performing some custom logic.

That said, teams generally do a pre-clean up because as you have just figured out, it is way more difficult to do a "post-cleanup" - and what happens if that fails as well. Maybe you should just log some transaction ids and do the clean up manually. Refer: https://stackoverflow.com/a/60944060/143475

This answer may give you some creative ideas. For example you can run a Java thread that keeps polling for any state changes in your database: https://stackoverflow.com/a/69406420/143475

Note that there are Gatling specific-ways to approach this:

https://stackoverflow.com/a/56729198/143475

End Gatling simulation when scenario fails BUT generate a report

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Of course I pre-cleanup my DB - the problem is that the simulation I am running produces DB clutter during the run - so I need to clear it also during the run. The database doesn't know that the Gatling user that was polling it has already ended, so the Java thread isn't the way either. The `RunetimeHook` could be the way, I will look into that. – Milan Smolík Oct 18 '21 at 12:18
  • In the end, the `afterScenario = ...` was indeed the solution – Milan Smolík Oct 20 '21 at 07:58