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

Constant Timer strange behavior when used with variables or functions #6162

Closed
KingRabbid opened this issue Nov 28, 2023 · 2 comments
Closed

Comments

@KingRabbid
Copy link

KingRabbid commented Nov 28, 2023

Expected behavior

When the value of a Constant Timer references a variable or a function call the following must be preserved (as it happens for a numeric value):

  1. Constant Timer runs after a PreProcessor
  2. Constant Timer does NOT run as the 1st element in a JMX

I see a problem with current behavior:

  1. Either the documentation should be clear about restriction to use anything else than numeric values and also implement a validation which rejects any other format value
  2. Or fix the current issue(s)

Note: I think Constant Timer is used by other timers (Random ones) so they may be impacted as well.

Actual behavior

I've spotted strange behavior from Constant Timer when the value references a variable or a function call:

  1. It runs as 1st element in a JMX
  2. It is executed before a JSR223PreProcessor (probably before any PreProcessor)

This is not valid if the value is entirely a numeric constant; this is also not valid for a JSR223Timer.

What I can see:

  1. Because Constant Timer's are executed as 1st elements from the tree when they are attached to the ThreadGroup then they throw NullPointerException because the variable is unknown (see JMX for tree structure)
  2. On Constant Timer branch in case of Flow Control Action 2 the timer is executed before the JSR223PreProcessor (visible in log and sampler timestamps) => this is not as per documentation
  3. Initially I've spotted the issue having Flow Control Action samplers and I thought it's an issue with them or in this combination; next I've used JSR223Sampler elements but outcome is the same.

jmeter.log
ConstantTimer-bug.zip

Steps to reproduce the problem

Attaching sample JMX; I do recommend to set log level to DEBUG to see sequence of execution better.

JMeter Version

5.6.2, 4.0

Java Version

OpenJDK 64-Bit v17.0.9

OS Version

Windows 11

@vlsi
Copy link
Collaborator

vlsi commented Dec 18, 2023

javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method toLong() on null object
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:158) ~[groovy-jsr223-3.0.17.jar:3.0.17]
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:231) ~[java.scripting:?]
	at org.apache.jmeter.functions.Groovy.execute(Groovy.java:123) [ApacheJMeter_functions.jar:5.6.2-SNAPSHOT]
	at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:139) [ApacheJMeter_core.jar:5.6.2-SNAPSHOT]
	at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:114) [ApacheJMeter_core.jar:5.6.2-SNAPSHOT]
	at org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:104) [ApacheJMeter_core.jar:5.6.2-SNAPSHOT]
	at org.apache.jmeter.testelement.property.AbstractProperty.getLongValue(AbstractProperty.java:128) [ApacheJMeter_core.jar:5.6.2-SNAPSHOT]
	at org.apache.jmeter.testelement.AbstractTestElement.getPropertyAsLong(AbstractTestElement.java:393) [ApacheJMeter_core.jar:5.6.2-SNAPSHOT]
	at org.apache.jmeter.timers.ConstantTimer.iterationStart(ConstantTimer.java:108) [ApacheJMeter_components.jar:5.6.2-SNAPSHOT]
	at org.apache.jmeter.control.GenericController.fireIterationStart(GenericController.java:412) [ApacheJMeter_core.jar:5.6.2-SNAPSHOT]
	at org.apache.jmeter.control.GenericController.fireIterEvents(GenericController.java:404) [ApacheJMeter_core.jar:5.6.2-SNAPSHOT]

The root cause is that constant timer evaluates delay at the "iteration start":

It is more-or-less the same as #6165 (comment)

@vlsi
Copy link
Collaborator

vlsi commented Dec 18, 2023

The list of impacted classes is: ConstantTimer (and derived classes), CompareAssertion, CSVDataSet, RandomVariableConfig

@vlsi vlsi closed this as completed in 1329c48 Dec 18, 2023
@vlsi vlsi added this to the 5.6.3 milestone Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants