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

Use current time as start time for OMTG #6353

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public long delay() {
nextEvent = events.next();
}
long now = System.currentTimeMillis();
long testStarted = JMeterContextService.getTestStartTime();
long testStarted = JMeterContextService.getContext().getThreadGroup().getStartTime();
long delay = (long) (nextEvent * TimeUnit.SECONDS.toMillis(1) + testStarted - now);
if (log.isDebugEnabled()) {
log.debug("Calculated delay is {}", delay);
Expand All @@ -117,7 +117,7 @@ public long delay() {
}

private EventProducer getEventProducer() {
long testStarted = JMeterContextService.getTestStartTime();
long testStarted = JMeterContextService.getContext().getThreadGroup().getStartTime();
long prevStarted = PREV_TEST_STARTED.get();
if (prevStarted != testStarted && PREV_TEST_STARTED.compareAndSet(prevStarted, testStarted)) {
// Reset counters if we are calculating throughput for a new test, see https://github.com/apache/jmeter/issues/6165
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ private void startThreadGroup(AbstractThreadGroup group, int groupCount, SearchB
threadGroupTree.add(group, testLevelElements);

groups.add(group);
group.setStartTime(System.currentTimeMillis());
group.start(groupCount, notifier, threadGroupTree, this);
} catch (JMeterStopTestException ex) { // NOSONAR Reported by log
JMeterUtils.reportErrorToUser("Error occurred starting thread group :" + group.getName()+ ", error message:"+ex.getMessage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public abstract class AbstractThreadGroup extends AbstractTestElement

private final AtomicInteger numberOfThreads = new AtomicInteger(0); // Number of active threads in this group

private long startTime;

@Override
public AbstractThreadGroupSchema getSchema() {
return AbstractThreadGroupSchema.INSTANCE;
Expand All @@ -97,6 +99,25 @@ public AbstractThreadGroupSchema getSchema() {
return new PropertiesAccessor<>(this, getSchema());
}

/**
* Get the time when this thread group has been started
* @since 6.0.0
* @return time in milliseconds since epoch
*/
public long getStartTime() {
return startTime;
}

/**
* Set the time when this thread group has been started.<br>
* Will probably be set by StandardJMeterEngine.
* @since 6.0.0
* @param startTime time in milliseconds since epoch
*/
public void setStartTime(long startTime) {
this.startTime = startTime;
}

/** {@inheritDoc} */
@Override
public boolean isDone() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public class OpenModelThreadGroup :
val seed = randomSeed
val rnd = if (seed == 0L) Random() else Random(seed)
val gen = ThreadScheduleProcessGenerator(rnd, parsedSchedule)
val testStartTime = JMeterContextService.getTestStartTime()
val testStartTime = this.startTime
val executorService = Executors.newCachedThreadPool()
this.executorService = executorService
val starter = ThreadsStarter(testStartTime, executorService, activeThreads, gen) { threadNumber ->
Expand Down
4 changes: 3 additions & 1 deletion xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ JMeter 6.x requires Java 17 or later for execution (Java 21 is recommended).
Summary
</p>
<ul>
<li><a href="#Bug fixes">Bug fixes</a></li>
<li><a href="#Changes">Changes</a></li>
</ul>

<ch_section>Changes</ch_section>
<h3>General</h3>
<ul>
<li><pr>6220</pr> Require Java 17 or later for running JMeter</li>
<li><pr>6274</pr> Change references to old MySQL driver to new class <code>com.mysql.cj.jdbc.Driver</code></li>
<li><issue>6352</issue> Calculate delays in Open Model Thread Group and Precise Throughput
Timer relative to start of Thread Group instead of the start of the test.</li>
</ul>

<!-- =================== Thanks =================== -->
Expand Down
Loading