vlsi commented on code in PR #6884:
URL: https://github.com/apache/jmeter/pull/6884#discussion_r4745749106
##########
src/core/src/main/java/org/apache/jmeter/control/TransactionController.java:
##########
@@ -221,10 +227,14 @@ private Sampler nextWithoutTransactionSampler() {
TransactionController.NUMBER_OF_SAMPLES_IN_TRANSACTION_PREFIX
+ calls + ", number of failing samples : "
+ noFailingSamples);
- if(res.isSuccessful()) {
+ if (res.isSuccessful()) {
res.setResponseCodeOK();
}
- notifyListeners();
+ if (hasChildSamples || !isThreadStopping()) {
+ notifyListeners();
+ } else {
+ res = null;
+ }
Review Comment:
**F12 major** No test shows that a transaction in which no sampler ran is
still reported while the thread keeps running, so dropping the thread-state
check in either mode leaves all 21 cases green.
Problem: The change drops an empty transaction only when the thread is
stopping. Every new case that expects no sample stops the thread, and every
case that expects a sample runs a sampler, so no case separates the two
conditions: a regression that drops every empty transaction, such as one whose
children an If Controller skipped, passes the suite in both modes.
```java
@ParameterizedTest(name = "[{index}] parent = {0}")
@ValueSource(booleans = {true, false})
void transactionWithoutExecutedSamplersOnARunningThreadIsReported(boolean
parent) {
// loop(1) -> [listener, sampler("before"), transaction ->
IfController("false") -> sampler("skipped")]
// run on a scheduled JMeterThread, as run(...) does
assertEquals(List.of("before", "transaction"), labels);
// head and base: passes
// with isThreadStopping() returning `thread != null`: [before] for
parent = false
// with `!running &&` removed from JMeterThread.java:669: [before] for
parent = true
}
```
##########
src/core/src/main/java/org/apache/jmeter/control/TransactionController.java:
##########
@@ -221,10 +227,14 @@ private Sampler nextWithoutTransactionSampler() {
TransactionController.NUMBER_OF_SAMPLES_IN_TRANSACTION_PREFIX
+ calls + ", number of failing samples : "
+ noFailingSamples);
- if(res.isSuccessful()) {
+ if (res.isSuccessful()) {
res.setResponseCodeOK();
}
- notifyListeners();
+ if (hasChildSamples || !isThreadStopping()) {
+ notifyListeners();
+ } else {
+ res = null;
+ }
Review Comment:
**F14 minor, medium confidence** In non-parent mode the empty-transaction
check guards only the end-of-children path and not triggerEndOfLoop, while
parent mode checks in doEndTransactionSampler, which both paths reach.
Problem: A non-parent transaction ended by a loop action (Start Next Thread
Loop, break, continue, or "Start next thread loop" on error) on a thread that
is already stopping is still reported with no child sample, against the
description's claim, while the same transaction in parent mode is dropped; the
next path that ends a non-parent transaction has to repeat the check.
Proposed solution: Decide it at the one place non-parent mode emits the
transaction: move the `hasChildSamples || !isThreadStopping()` test into
TransactionController.notifyListeners(), dropping `res` when it fails, so that
nextWithoutTransactionSampler and triggerEndOfLoop both go through it, as both
parent-mode paths go through doEndTransactionSampler.
##########
src/core/src/main/java/org/apache/jmeter/threads/JMeterThread.java:
##########
@@ -665,6 +665,12 @@ private SampleResult doEndTransactionSampler(
SampleResult transactionResult =
transactionSampler.getTransactionResult();
fillThreadInformation(transactionResult,
threadGroup.getNumberOfThreads(), JMeterContextService.getNumberOfThreads());
+ // A transaction that the stopping thread never executed anything in
is not a measurement
Review Comment:
**F15 minor** The comment says the stopping thread "never executed anything"
in the transaction, but the check finds only that no sampler produced a
sub-result: the timer or pre-processor that stopped the thread, and a Flow
Control Action, did execute.
```suggestion
// No sampler in the transaction produced a sample before the thread
stopped, so report no transaction sample
```
##########
src/components/src/test/java/org/apache/jmeter/control/TestTransactionController.java:
##########
@@ -81,4 +94,149 @@ public void testIssue57958() throws Exception {
assertEquals("Number of samples in transaction : 1, number of failing
samples : 1",
listener.getEvents().get(0).getResult().getResponseMessage());
}
+
+ /** Stops the thread before the sampler: overruns the schedule, or throws
as Precise Throughput Timer does. */
+ private static class StoppingTimer extends AbstractTestElement implements
Timer {
+ private static final long serialVersionUID = 1L;
+ private final boolean throwing;
+
+ StoppingTimer(boolean throwing) {
+ this.throwing = throwing;
+ }
+
+ @Override
+ public long delay() {
+ if (throwing) {
+ throw new JMeterStopThreadException();
+ }
+ return 60_000;
+ }
+ }
Review Comment:
**F18 nit** StoppingTimer(true) is the same timer as ThrowingTimer(new
JMeterStopThreadException()); addSkippedSampler could use ThrowingTimer and
StoppingTimer could go.
Problem: A reader has to compare the two classes to see that the `throwing =
true` cases and the stop-test cases differ only in the exception type.
Proposed solution: In addSkippedSampler, add `throwing ? new
ThrowingTimer(new JMeterStopThreadException()) : <a timer returning 60_000>`
and delete StoppingTimer; move its Javadoc about Precise Throughput Timer to
addSkippedSampler. The overrunning timer can be OverrunOnSecondCallTimer
generalized to the number of calls that return 0.
##########
src/core/src/main/java/org/apache/jmeter/threads/JMeterThread.java:
##########
@@ -819,6 +825,11 @@ public String getThreadName() {
return threadName;
}
+ @API(status = API.Status.INTERNAL, since = "6.0.0")
+ public boolean isRunning() {
Review Comment:
**F16 minor** The new public JMeterThread.isRunning() has no Javadoc, so a
caller cannot tell that it returns true before run() starts and false while the
thread is still ending its open transactions.
Problem: A reader who knows Thread.isAlive() reads the name as liveness; the
only caller, TransactionController.isThreadStopping(), reads false as
"stopping" from the thread itself.
```suggestion
/**
* Returns whether this thread will run more samplers. It is {@code
true} from construction, before
* {@link #run()} starts, and turns {@code false} for good when the
thread is told to stop ({@link #stop()},
* Stop Test, Shutdown, or a stop exception from a test element), when
its scheduled end time is reached or a
* timer's delay would pass it, or when its loops are done.
* The thread may still be ending its open transactions while this
returns {@code false}.
*
* @return {@code false} once the thread has started to stop
*/
@API(status = API.Status.INTERNAL, since = "6.0.0")
public boolean isRunning() {
```
##########
xdocs/usermanual/component_reference.xml:
##########
@@ -2564,6 +2564,10 @@ attempts to open the <code>Filename</code> relative to
the JMX launch directory.
The Transaction Controller generates an additional
sample which measures the overall time taken to perform the nested
test elements.
</p>
+ <p>
+ When the thread stops before any sampler in the controller runs, for
example at a timer whose delay would end
+ after the scheduled end of the test, the controller generates no
sample.
+ </p>
Review Comment:
**F20 nit** The new paragraph sits between the first paragraph and the note
whose "the time" refers to it; move it after "The generated sample is only
regarded as successful if all its sub-samples are successful."
Problem: After the insertion, the note "the time includes all processing
within the controller scope" follows a sentence that says no sample is
generated, and the rare case comes before the two modes and how the time is
measured.
##########
xdocs/usermanual/component_reference.xml:
##########
@@ -2564,6 +2564,10 @@ attempts to open the <code>Filename</code> relative to
the JMX launch directory.
The Transaction Controller generates an additional
sample which measures the overall time taken to perform the nested
test elements.
</p>
+ <p>
+ When the thread stops before any sampler in the controller runs, for
example at a timer whose delay would end
+ after the scheduled end of the test, the controller generates no
sample.
Review Comment:
**F13 minor, medium confidence** The Transaction Controller page and the
changelog say no sample is generated when the thread stops "before any sampler
in the controller runs", but both modes drop the sample whenever no sampler
produced one, so a transaction in which a Flow Control Action ran, or whose
sampler result was ignored, is dropped too.
Problem: The Flow Control Action page recommends it inside a Transaction
Controller to add pauses without a sample. A user whose transaction holds a
Flow Control Action (a pause, or Stop Thread under an If Controller) and whose
thread stops there reads that a sampler ran and expects the transaction sample;
the change drops it.
```java
// In TestTransactionController, with the run(...) helper
TestAction stop = new TestAction();
stop.setAction(TestAction.STOP);
stop.setTarget(TestAction.THREAD);
List<String> labels = run(parent, tx -> tx.add(stop));
// current: [] for parent = true and false, although a sampler (Flow Control
Action) ran
// the page and the changelog describe the dropped case only as "before any
sampler runs"
```
Proposed solution: Word the changelog entry for the same condition: "Do not
report a Transaction Controller sample when the thread stops before any sampler
in the transaction produces a sample, for example at a timer whose delay would
end after the scheduled end of the test. Such samples took close to 0 ms and
distorted the minimum response time."
```suggestion
When the thread stops before any sampler in the controller produces
a sample, for example at a timer whose delay
would end after the scheduled end of the test, the controller
generates no sample.
```
##########
src/components/src/test/java/org/apache/jmeter/control/TestTransactionController.java:
##########
@@ -81,4 +94,149 @@ public void testIssue57958() throws Exception {
assertEquals("Number of samples in transaction : 1, number of failing
samples : 1",
listener.getEvents().get(0).getResult().getResponseMessage());
}
+
+ /** Stops the thread before the sampler: overruns the schedule, or throws
as Precise Throughput Timer does. */
+ private static class StoppingTimer extends AbstractTestElement implements
Timer {
+ private static final long serialVersionUID = 1L;
+ private final boolean throwing;
+
+ StoppingTimer(boolean throwing) {
+ this.throwing = throwing;
+ }
+
+ @Override
+ public long delay() {
+ if (throwing) {
+ throw new JMeterStopThreadException();
+ }
+ return 60_000;
+ }
+ }
+
+ private static class ThrowingTimer extends AbstractTestElement implements
Timer {
+ private static final long serialVersionUID = 1L;
+ private final RuntimeException stop;
+
+ ThrowingTimer(RuntimeException stop) {
+ this.stop = stop;
+ }
+
+ @Override
+ public long delay() {
+ throw stop;
+ }
+ }
+
+ private static class StoppingPreProcessor extends AbstractTestElement
implements PreProcessor {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void process() {
+ throw new JMeterStopThreadException();
+ }
+ }
+
+ private static class OverrunOnSecondCallTimer extends AbstractTestElement
implements Timer {
+ private static final long serialVersionUID = 1L;
+ private int calls;
+
+ @Override
+ public long delay() {
+ return calls++ == 0 ? 0 : 60_000;
+ }
+ }
+
+ @ParameterizedTest(name = "[{index}] parent = {0}, throwing = {1}")
+ @CsvSource({"true,true", "true,false", "false,true", "false,false"})
+ void transactionWithoutExecutedSamplersIsNotReported(boolean parent,
boolean throwing) {
+ assertEquals(List.of(), run(parent, tx -> addSkippedSampler(tx,
throwing)));
+ }
+
+ @ParameterizedTest(name = "[{index}] parent = {0}, throwing = {1}")
+ @CsvSource({"true,true", "true,false", "false,true", "false,false"})
+ void stopInsideInnerTransactionReportsNeitherTransaction(boolean parent,
boolean throwing) {
+ assertEquals(List.of(),
+ run(parent, tx -> addSkippedSampler(addTransaction(tx,
"inner", parent), throwing)));
+ }
Review Comment:
**F17 minor** No test covers an empty inner transaction inside an outer
transaction where a sampler ran, though the change drops the inner sample there
in non-parent mode.
Problem: stopInsideInnerTransactionReportsNeitherTransaction covers only an
outer transaction in which nothing ran. With a sampler in the outer and the
stop in the inner, the two transactions take opposite branches of the new
condition, and nothing pins that the outer is still reported and the inner is
not.
```java
List<String> labels = run(parent, tx -> {
tx.add(sampler("executed"));
addSkippedSampler(addTransaction(tx, "inner", parent), throwing);
});
// head: parent -> [transaction], non-parent -> [executed, transaction]
// base, non-parent: [executed, inner, transaction]
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]