Calling Karate feature file returns response object including multiple copies of previous response object of parent scenario

Viewed 617

I am investigating exponential increase in JAVA heap size when executing complex scenarios especially with multiple reusable scenarios. This is my attempt to troubleshoot the issue with simple example and possible explanation to JVM heap usage.

Environment: Karate 1.1.0.RC4 | JDK 14 | Maven 3.6.3

Example: Download project, extract and execute maven command as per READEME

Observation: As per following example, if we call same scenario multiple times, response object grows exponentially since it includes response from previous called scenario along with copies of global variables.

  @unexpected
  Scenario: Not over-writing nested variable
    * def response = call read('classpath:examples/library.feature@getLibraryData')
    * string out = response
    * def resp1 = response.randomTag
    * karate.log('FIRST RESPONSE SIZE = ', out.length)

    * def response = call read('classpath:examples/library.feature@getLibraryData')
    * string out = response
    * def resp2 = response.randomTag
    * karate.log('SECOND RESPONSE SIZE = ', out.length)

Output:
10:26:23.863 [main] INFO  c.intuit.karate.core.FeatureRuntime - scenario called at line: 9 by tag: getLibraryData
10:26:23.875 [main] INFO  c.intuit.karate.core.FeatureRuntime - scenario called at line: 14 by tag: libraryData
10:26:23.885 [main] INFO  com.intuit.karate - FIRST RESPONSE SIZE =  331 
10:26:23.885 [main] INFO  c.intuit.karate.core.FeatureRuntime - scenario called at line: 9 by tag: getLibraryData
10:26:23.894 [main] INFO  c.intuit.karate.core.FeatureRuntime - scenario called at line: 14 by tag: libraryData
10:26:23.974 [main] INFO  com.intuit.karate - SECOND RESPONSE SIZE =  1783 
10:26:23.974 [main] INFO  c.intuit.karate.core.FeatureRuntime - scenario called at line: 9 by tag: getLibraryData
10:26:23.974 [main] INFO  c.intuit.karate.core.FeatureRuntime - scenario called at line: 14 by tag: libraryData
10:26:23.988 [main] INFO  com.intuit.karate - THIRD RESPONSE SIZE =  8009 
  1. Do we really need to include response and global variables in the response of called feature file (non-shared scope)?
  2. When we read large json file and call multiple reusable scenario files, each time copy of read json data gets added to response object. Is there way to avoid this behavior?
  3. Is there a better way to script complex test using reusable scenarios without having multiple copies of same variables?
1 Answers
Related