You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jmeter.apache.org by "artemkurov (via GitHub)" <gi...@apache.org> on 2024/08/01 16:55:38 UTC

[I] Listeners receive null as a property value inside a groovy script when run from CLI [jmeter]

artemkurov opened a new issue, #6323:
URL: https://github.com/apache/jmeter/issues/6323

   ### Expected behavior
   
   `${__groovy(props.get("baseDir")+"/results/latency_data.csv")}` evaluated to correct file path like `/Users/username/projects/qa-perf/performance/jmeter/results/latency_data.csv`
   
   ### Actual behavior
   
   `${__groovy(props.get("baseDir")+"/results/latency_data.csv")}` evaluates to `null/results/latency_data.csv`
   <img width="364" alt="image" src="https://github.com/user-attachments/assets/d8cd6668-606a-422b-9119-9153708fbcde">
   
   
   ### Steps to reproduce the problem
   
   ### Prerequisites:
   Having a test plan (attached here [bug.jmx.zip](https://github.com/user-attachments/files/16459604/bug.jmx.zip)), containing:
   - setUp thread group, which contains 
   --- init JSR223 Sampler
   - main thread group with 
   --- Dummy sampler
   --- Simple Data Writer (or any listener)
   - tear down thread group with
   --- JSR223 Sampler
   
   init JSR223 Sampler having this code:
   ```
   import org.apache.jmeter.util.JMeterUtils;
   import org.apache.jmeter.services.FileServer
   
   // Do not show this sampler in report
   SampleResult.setIgnore()
   
   // Set base directory. Mainly needed for local run
   String baseDir = FileServer.getFileServer().getBaseDir()
   JMeterUtils.setProperty("baseDir", baseDir)
   log.info("Base directory set to " + props.get('baseDir'))
   ```
   
   Simple Data Writer having this as a filename:
   `${__groovy(props.get("baseDir")+"/results/latency_data.csv")}`
   
   Tear down JSR223 Sampler having this code:
   ```
   // Do not show this sampler in report
   SampleResult.setIgnore()
   
   String filePath = props.get('baseDir') + '/results/latency_data.csv'
   log.info('filepath=' + filePath)
   File file = new File(filePath);
   if(!file.exists()) {
   	log.error('FILE NOT FOUND')
   }
   
   // Pasre file
   //...
   ```
   
   ### Reproducing
   1. Run test plan from GUI.
   2. Observe `/Users/username/projects/qa-perf/performance/jmeter/results/latency_data.csv` file is created and no errors in the log
   3. Launch terminal in baseDir folder (for me is `/Users/username/projects/qa-perf/performance/jmeter`)
   4. Launch the same test plan via CLI using command
   `jmeter -LINFO -n -j Buggy_Test_Plan.log -t bug.jmx -l Buggy_Test_Plan.jtl`
   5. Observe unexpected behavior:
   - File `/Users/username/projects/qa-perf/performance/jmeter/null/results/latency_data.csv` is created
   - ERROR in logs because JSR223 sampler could not find the file.
   - `INFO o.a.j.r.ResultCollector: Folder at /Users/username/projects/qa-perf/performance/jmeter/null/results was created`
   
   I assume that folder `null` is created because this happens before set of the variable `baseDir`, thus `props.get("baseDir")` returns null.
   But this flow does work through GUI mode, so should be a bug.
   
   
   
   
   ### JMeter Version
   
   5.6.3
   
   ### Java Version
   
   openjdk 17.0.11 2024-04-16
   
   ### OS Version
   
   MacOS Sonoma 14.5 (also reproducable on Alpine Linux in Docker container)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@jmeter.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Listeners create folder with null path when path is evaluated as a property value inside a groovy script when run from CLI [jmeter]

Posted by "artemkurov (via GitHub)" <gi...@apache.org>.
artemkurov commented on issue #6323:
URL: https://github.com/apache/jmeter/issues/6323#issuecomment-2282191774

   Ok I understand now. Thank you for explanation. Issue could be closed now.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@jmeter.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Listeners create folder with null path when path is evaluated as a property value inside a groovy script when run from CLI [jmeter]

Posted by "FSchumacher (via GitHub)" <gi...@apache.org>.
FSchumacher commented on issue #6323:
URL: https://github.com/apache/jmeter/issues/6323#issuecomment-2280731085

   I think you are out of luck here. The listeners are initialized before any sampler has been run and I believe the filename is set on initialization.
   
   I wonder though, why you took the route through the groovy function to get the property instead of using the [P-function](https://jmeter.apache.org/usermanual/functions.html#__P). It would not work in this case, either, but is seems more straightforward.
   
   Things, that should work include:
   * using Fileserver inside a groovy function to set the filename (instead of taking the route via a runtime set property)
   * using a property set via command line 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@jmeter.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org