The way of running karate tests in parallel - question

Adam :

I have a question:) How does it work karate if it comes to parallel execution? We use karate in specific way where under the hood we hava a bunch of java code. I'm curious if variables declared as ThreadLocal in our java code is really thread save? Is each test run in separate thread or there is another way of running test simultaneously? The problem we faced is that it looks like a least two of running tests have access to ThreadLocal variable which should be isolated from each other. Could you explain?

Peter Thomas :

If you use a ThreadLocal you are on your own :) The short answer is Karate will create a thread-pool for Scenario execution, and each Scenario can go onto any of these threads. Maybe you need to read this section on how you can force some Scenario-s to run in sequence - but you may still have problems if the ones that ran first do not "clean up".

EDIT: I also think it should NOT be possible for 2 Scenarios to be on the same thread at the same time and if you are seeing this - it is a bug, please help us replicate it (see last line of my answer).

Karate's multi threading is battle-tested and we would not be able to claim that you can do the Gatling integration if this was not the case. Maybe you should just trust Karate for doing all the heavy lifting you need ? For example look at "hooks": https://github.com/intuit/karate#hooks

And of course, if you really do think there's an issue, follow this process please: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=141113&siteId=1