Skip to content

Commit

Permalink
fix: log errors happening while JMeter starts the test
Browse files Browse the repository at this point in the history
Previously, the exceptions from TestStateListener.testStarted might
be unnoticed since the UI did not display them.

This change is a workaround to surface errors in common cases.

See apache#6174
  • Loading branch information
vlsi committed Dec 19, 2023
1 parent 1329c48 commit e9c2ef9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import java.io.Serializable;

import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.engine.event.LoopIterationListener;
import org.apache.jmeter.testelement.AbstractTestElement;
import org.apache.jmeter.util.JMeterUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,21 @@ private static void removeThreadGroups(List<?> elements) {

private void notifyTestListenersOfStart(SearchByClass<? extends TestStateListener> testListeners) {
for (TestStateListener tl : testListeners.getSearchResults()) {
if (tl instanceof TestBean) {
TestBeanHelper.prepare((TestElement) tl);
}
if (host == null) {
tl.testStarted();
} else {
tl.testStarted(host);
try {
if (tl instanceof TestBean) {
TestBeanHelper.prepare((TestElement) tl);
}
if (host == null) {
tl.testStarted();
} else {
tl.testStarted(host);
}
} catch (Throwable e) {
// TODO: we should not be logging the exceptions multiple times, however, currently GUI does not
// monitor if the running test fails, so we log the exception for the users to see in the logs
log.error("Unable to execute testStarted({}) for test element {}", host, tl, e);
throw new IllegalStateException(
"Unable to execute testStarted(" + host + ") for test element " + tl, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,25 @@ public static void prepare(TestElement el) {
try {
for (CachedPropertyDescriptor desc : GOOD_PROPS.get(el.getClass())) {
// Obtain a value of the appropriate type for this property.
JMeterProperty jprop = el.getProperty(desc.descriptor.getName());
Class<?> type = desc.propertyType;
Object value = unwrapProperty(desc.descriptor, jprop, type);

JMeterProperty jprop;
Object value;
try {
jprop = el.getProperty(desc.descriptor.getName());
value = unwrapProperty(desc.descriptor, jprop, type);
} catch (OutOfMemoryError | StackOverflowError e) {
throw e;
} catch (Throwable e) {
String elementName;
try {
elementName = el.getName();
} catch(Throwable ignore) {
elementName = el.getClass().getName();
}
throw new IllegalStateException(
"Can't retrieve property '" + desc.descriptor.getName() + "' of element " + elementName, e);
}

if (log.isDebugEnabled()) {
log.debug("Setting {}={}", jprop.getName(), value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ public class TimeFunction extends AbstractFunction implements TestStateListener
long div = Long.parseLong(fmt.substring(1)); // should never case NFE
return () -> Long.toString(System.currentTimeMillis() / div);
}
DateTimeFormatter df = DateTimeFormatter
.ofPattern(fmt)
.withZone(ZoneId.systemDefault());
DateTimeFormatter df;
try {
df = DateTimeFormatter
.ofPattern(fmt)
.withZone(ZoneId.systemDefault());
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Unable to parse date format " + fmt, e);
}
if (isPossibleUsageOfUInFormat(df, fmt)) {
log.warn(
MessageFormat.format(
Expand Down

0 comments on commit e9c2ef9

Please sign in to comment.