My test plan structure is
Thread Group
--Http request
while loop controller
--http request
--regular expression extractor (get a login config key which is used in while loop)
Regular expression:-"business_type":"(.+?)"
variable name :-business_type
while loop condition: :- ${__javaScript(("${business_type}" === "Apparel & Footwear" && ${counter} < 5),)
I want to stop while loop when the expected business type is found in response.
You need to check 2 condition while one for negative equal the string in While Controller:
${__jexl3(${counter} < 5 && "${business_type}" != "Apparel & Footwear")}
Prefer __jexl3 over __javascript function:
Checking this and using __jexl3 or __groovy function in Condition is advised for performances
Try using "!=" instead of "===".
${__javaScript("${business_type}" != "Apparel & Footwear" && ${counter} < 5)}
Related
Simple code there-
let $sV2 :=''
for $i in (1 to 2)
let $sV1 := 'test1'
let $sV2 := if (fn:string-length($sV2) != 0) then fn:concat($sV2,'||',$sV1) else ($sV1)
return
<test>{$sV2}</test>
i get the same output
<test>test1</test>
<test>test1</test>
whereas i expect
<test>test1</test>
<test>test1||test1</test>
what am i doing wrong? i tried to debug but why does V2 initialize to null/'' for second iteration.
Note- I have to use xquery 1.0 do to some product limitations.
How do i get the expected output?
XQuery is a functional language. As such, it does not allow you to change the value of a variable once it has been assigned.
There are many other ways to reach the same results, though. Your specific query can e.g. be rewritten as follows:
for $i in 1 to 2
return <test>{
string-join(for $n in 1 to $i return 'test1', '||')
}</test>
If we want to execute a thread group with 2 concurrent users only when IP Address is not in (10.0.0.1, 10.0.0.2). How can we achieve this?
I have used below condition but its not working
${__groovy(if ((org.apache.jmeter.util.JMeterUtils.getLocalHostIP()!='10.0.0.1') || (org.apache.jmeter.util.JMeterUtils.getLocalHostIP()!='10.0.0.2')) return '2' else return '0',)}
I believe you need to change || operator to && operator
${__groovy(if ((org.apache.jmeter.util.JMeterUtils.getLocalHostIP()!='10.10.10.1') && (org.apache.jmeter.util.JMeterUtils.getLocalHostIP()!='10.0.0.2')) return '2' else return '0',)}
You can also consider slightly changing syntax so it would be more readable and it would be easier to add next IPs if needed:
${__groovy(if (['10.0.0.1'\, '10.0.0.2'].contains(org.apache.jmeter.util.JMeterUtils.getLocalHostIP())) return '0' else return '2',)}
More information:
Apache Groovy - Logical Operators
Apache Groovy - Why and How You Should Use It
Terraform variable validation for CIDR, looking alternative for regex
Below is the tested code in Terraform version 13.0
is there any alternative way to achieve same thing with not using regex?
cidr block - start 172.28.0.0.0/16
variable "vpc_cidr" {
description = "Kubernetes cluster CIDR notation for vpc."
validation {
condition = can(regex("^([0-9]{1,3}\\.){3}[0-9]{1,3}($|/(16))$", var.pod_cidr))
error_message = "Vpc_cidr value must be greater than 172.0.0.0/16."
}
}
how to validate CIDR block 172.28.x.x/16 with cidrsubnet function?
https://www.terraform.io/docs/language/functions/cidrsubnet.html
validation condition - if IP range is outof 172.28.x.x/16 then validation will be failed
I can't think of a direct way to achieve what you want with the functions in today's Terraform, but I think we can break the check into two conditions that, taken together, lead to the same effect:
The zeroth address in the subnet must be 172.28.0.0.
The netmask of the range must be 255.255.0.0.
We can test these two rules using two expressions:
cidrhost(var.vpc_cidr, 0) == "172.28.0.0"
cidrnetmask(var.vpc_cidr) == "255.255.0.0"
Both of these functions can fail if given something that isn't valid CIDR block syntax at all, and cidrnetmask will additionally fail if given an IPv6 address, so we can add try guards to both of them to turn that error into a false result as condition expects:
try(cidrhost(var.vpc_cidr, 0), null) == "172.28.0.0"
try(cidrnetmask(var.vpc_cidr), null) == "255.255.0.0"
The try function will return the result of the first expression that doesn't produce a dynamic error, so in the above examples an invalid input to the cidrhost or cidrnetmask function will cause an expression like null == "172.28.0.0", which will always be false and thus the condition will still not be met.
Finally, we can combine these together using the && operator to get the complete condition expression:
condition = (
try(cidrhost(var.vpc_cidr, 0), null) == "172.28.0.0" &&
try(cidrnetmask(var.vpc_cidr), null) == "255.255.0.0"
)
You have one 0 to many and it should be greater then 172.0.0.0/16. For example:
172.1.0.0/16
not:
172.0.0.0.0/16
A bit of hack, but still:
variable "vpc_cidr" {
validation {
condition = cidrsubnet("${var.pod_cidr}/16", 0, 0) == "172.28.0.0/16"
}
}
I prefer the solution from https://dev.to/drewmullen/terraform-variable-validation-with-samples-1ank
variable "string_like_valid_ipv4_cidr" {
type = string
default = "10.0.0.0/16"
validation {
condition = can(cidrhost(var.string_like_valid_ipv4_cidr, 32))
error_message = "Must be valid IPv4 CIDR."
}
}
Also note, as commented there, that the condition requires a modification to work for /32 addresses.
Following condition in if controller is not working
(${__threadNum} =="1" || ${__threadNum} % 5 == "0") && ("${__iterationNum}"=="1")
You have types mismatch in your expression, you should amend it to:
(${__threadNum} ==1 || ${__threadNum} % 5 == 0) && ${__iterationNum} == 1
Also make sure you have Custom JMeter Functions bundle installed, it can be done using JMeter Plugins Manager
In case of any problems take a look at jmeter.log file, it should contain all necessary troubleshooting information.
need to put double quotes... ""
"${__threadNum}"==1 :::
("${__threadNum}"==1 ||"${__threadNum}"==0)&&("${__iterationNum}"==1)
Hi My answer may be helpful for someone else as well
${__groovy(vars.get("country) != "${Current_Country}" || vars.get("State") != "${__V(State_${Counter})}")}
Is it possible to add two conditions in while controller? My two conditions are Complete ="True" and Results >200.
I tried using it by setting Complete = False and Results=0 in user defined variables and used it in while controller as follows:
${__javaScript("${Complete}" != "true")} && ${__javaScript((parseInt(${Results}) >90)}.
But it is looping indefinitely. Please help.
Try the following condition (working for me):
${__jexl3("${Complete}" == "False" && ${Results} >= 0,)}
where Complete - False & Results - 0.
For above values, condition will be evaluated to true, hence executes the children of the While Controller.
Note: Please change the conditions == & >= symbols and values False && 0 as per your requirements.
You must reset the values inside the While Controller, to make the condition evaluated to false, otherwise you will struck in infinite loop.
References:
https://jmeter.apache.org/usermanual/component_reference.html#While_Controller
https://www.blazemeter.com/blog/using-while-controller-jmeter
For Multiple Condition in While Loop using Groovey Function for '&&' and '||' for the same field.
${__groovy(!(vars.get('ocrstatus_1').equals('500') || vars.get('ocrstatus_1').equals('1000')) ,)}