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

The Constant Throughput Timer is throwing a NullPointerException when using variables (vars.get) in "Target Throughput"-field #6165

Closed
cslfst opened this issue Dec 1, 2023 · 2 comments · Fixed by #6192
Labels
Milestone

Comments

@cslfst
Copy link

cslfst commented Dec 1, 2023

Expected behavior

The Constant Throughput Timer is supposed to ensure the number of times a Use Case is executed within a minute.
How often the Use Case ist executed depends on the value specified in the Field "Target troughput (in samples per minute)"
The value in this case is a variable (${__groovy( vars.get("throughput").toDouble() )}).

Actual behavior

The Use Case is not being executed once and while the test is still running, no further actions are executed. It is stuck.
A NullPointerException occures: javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method toDouble() on null object.
The Issue #6162 might be similar.

Steps to reproduce the problem

The attached test.jmx should reproduce the problem.

jmeter.log
test.zip

The Constant Throughput Timer works as expcted with jmeter 5.5 and older, dispite having the same NullPointerException.

JMeter Version

5.6.2

Java Version

openjdk version "11.0.19" 2023-04-18 LTS

OS Version

Microsoft Windows [Version 10.0.14393]

@cslfst
Copy link
Author

cslfst commented Dec 1, 2023 via email

@vlsi
Copy link
Collaborator

vlsi commented Dec 18, 2023

Root cause

  1. ConstantThroughputTimer implements TestStateListener as it wants to reset state when the test begins
  2. ConstantThroughputTimer is TestBean, so JMeter attempts computing all the properties before calling constantThroughputTimer.testStarted()

As vars.put("throughput", ...) happens during the test only, JMeter can't resolve throughput value for ConstantThroughputTimer, so it fails with NPE.

Unfortunately, it is quite common for elements to implement TestStateListener and TestBean at the same time, so the issue might impact many use cases.

At the same time, JMeter can't predict which properties would indeed be needed for execution of testStarted(), so JMeter has to conservatively compute all the variables.

Impacted classes

KeystoreConfig, SyncTimer, BoltConnectionElement, DataSourceElement, MongoSourceElement

Workarounds

The workaround could be writing vars.get("throughput") in such a way so it does not fail when "throughput" variable is missing (before the first execution).

Another workaround could be using properties rather than variables. Of course, properties are global across threads, however, it might be enough in certain cases.

Long-term solution

a) Add "variable declaration" block, so users could declare variables along with their initial values
b) Avoid implements TestBean, TestStateListener pattern. The problematic case is testStarted(), so it could be replaced with org.apache.jmeter.threads.JMeterContextService#getTestStartTime and something else to reset values once
c) Another alternative is "avoid calling org.apache.jmeter.testbeans.TestBeanHelper#prepare before calling .testStarted". There's no way to evaluate variables, so we could jsut ignore it and hope .testStarted will not use properties that require variables. Unfortunately, it would be hard or impossible to detect cases when a test element attempts to access the state

vlsi added a commit to vlsi/jmeter that referenced this issue Dec 18, 2023
…nd PreciseThroughputTimer

Previously, the timers might fail initialization in case variable was not present
when test started.

The current workaround is to avoid implementing TestStateListener in the timers
so JMeter does not attempt evaluating all the properties before test starts.

fixes apache#6165
@vlsi vlsi added this to the 5.6.3 milestone Dec 18, 2023
@vlsi vlsi removed the to-triage label Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants