Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variable support for Include Controller #679

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

polarnik
Copy link

@polarnik polarnik commented Dec 9, 2021

  • Add variable support for includePath
  • Add tests for getIncludePathAsFunction()

Description

The IncludePath field has added support for variables.

Motivation and Context

I want to use files in Include Controller whose names are set in variables.

For Example 1.
I want to run the test with loading static resources and without loading static resources.
Static resources - 200 links.
If I use If Controller, then an optional block with static resources will be in the script, it will take up memory.
If I use Include Controller with variable support, then optional block with 200 links may be change for block with 0 links. A block with 0 links will not take up memory.

For Example 2.
I work in a large team. We decided to change the Access Token update block in all scenarios. From the test_fragment_refresh_Access Token_v1.jms option to test_fragment_refresh_Access Token_v2.jmx. 10 scripts.

Instead of 10 changes in the scripts. The function ${__property(text_fragment_refresh_access Token)} or ${__P(text_fragment_refresh_access Token)} will be used. And there will be one change in user.property.

How Has This Been Tested?

I write some tests.
And test via gradle runGui.
For troubleshooting: add debug loggings.

Screenshots (if appropriate):

Fail load:
image

Ok load, debug logging:
image

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.

==============

- Add variable support for includePath
- Add tests for getIncludePathAsFunction()
Comment on lines +97 to +121
/**
* return the JMX file path with function support.
* @return the JMX file path with function support
*/
public String getIncludePathAsFunction()
{
String jmxfile = this.getPropertyAsString(INCLUDE_PATH);
CompoundVariable masterFunction = new CompoundVariable();
try{
log.debug("Trying to evaluate 'Include Path' as an expression: {}", jmxfile);
masterFunction.setParameters(jmxfile);
if(masterFunction.hasFunction()) {
String jmxfileCompile = masterFunction.getFunction().execute();
log.debug("The value of 'Include Path' is computed as: {}", jmxfileCompile);
return jmxfileCompile;
}
} catch (InvalidVariableException e)
{
log.warn("Invalid variable in 'Include Path' {}. See log for details", jmxfile);
log.warn("Invalid variable in 'Include Path':", e);
}

log.debug("The value of 'Include Path' is simple string: {}", jmxfile);
return jmxfile;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the wrong approach to attack the problem. It looks like includePath.setRunningVersion(true).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if apply includePath.setRunningVersion(true)
and set includePath like ${__P(somePropName, 'defaultValue')}
and open JMX File in GUI Mode

then includePath view like value of somePropName or 'defaultValue', but not view as ${__P(somePropName, 'defaultValue')}

Copy link
Author

@polarnik polarnik Dec 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getIncludePathAsFunction() did not change value of includePath. Function getIncludePathAsFunction() used instead of simple this.getPropertyAsString(INCLUDE_PATH) for variables and functions support without change of value includePath.

Script developer may open JMX file in GUI mode, press Save button, and JMX file was saved without changes.

If used includePath.setRunningVersion(true), then after open JMX script in GUI mode and press Save button - original expression will be replaced with expression value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK setRunningVersions(tue) should be called just before script execution (like it is called for other elements)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I try tested this

@codecov-commenter
Copy link

codecov-commenter commented Dec 25, 2021

Codecov Report

Attention: Patch coverage is 80.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 55.58%. Comparing base (edc7727) to head (be21f47).
Report is 735 commits behind head on master.

Files with missing lines Patch % Lines
...a/org/apache/jmeter/control/IncludeController.java 80.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #679   +/-   ##
=========================================
  Coverage     55.57%   55.58%           
- Complexity    10333    10335    +2     
=========================================
  Files          1059     1059           
  Lines         65055    65065   +10     
  Branches       7403     7400    -3     
=========================================
+ Hits          36156    36167   +11     
  Misses        26349    26349           
+ Partials       2550     2549    -1     
Files with missing lines Coverage Δ
...a/org/apache/jmeter/control/IncludeController.java 59.78% <80.00%> (+3.37%) ⬆️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update edc7727...be21f47. Read the comment docs.

@ClemRz
Copy link

ClemRz commented Jun 6, 2023

Hi,

I see this PR is still open. It is from 2021. Is there any reason this didn't make it into master?
I badly need this feature.
Thx

@vlsi
Copy link
Collaborator

vlsi commented Jun 6, 2023

@ClemRz , could you please clarify your use case in more detail?

vlsi added a commit to vlsi/jmeter that referenced this pull request Jun 8, 2023
vlsi added a commit to vlsi/jmeter that referenced this pull request Jun 9, 2023
vlsi added a commit to vlsi/jmeter that referenced this pull request Jun 13, 2023
vlsi added a commit to vlsi/jmeter that referenced this pull request Jun 13, 2023
vlsi added a commit to vlsi/jmeter that referenced this pull request Jun 14, 2023
@ClemRz
Copy link

ClemRz commented Jun 14, 2023

@vlsi
We have a pipeline that runs ~50 jmx files simultaneously and we have to use a bash script to replace the value of the include controller using sed in a main.jmx file for each one of those ~50 builds. It's not ideal nor future-proofed.

vlsi added a commit to vlsi/jmeter that referenced this pull request Jun 15, 2023
@jlerbsc
Copy link

jlerbsc commented Apr 24, 2024

Have these changes been integrated into version 5.6.3?

I'm also interested in the possibility of testing 2 different authentication modes. Indeed, JMeter scripts must be used in 2 environments with different authentication modes (migration in progress). At present, I have to duplicate all the scripts to be able to run tests on these 2 environments. With this possibility, we could declare the JMeter authentication module to be used in the script launch parameters.

@germanbisogno
Copy link

+1 for this feature to be implemented, notice Azure Load test doesn't support yet using test fragments, see microsoft/azure-load-testing#77, by this implementation it maybe possible to refer to JMX files directly in Azure using variables.

Thanks,

Ger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants