在脚本开头获取并发线程组的初始预期测试持续时间或结束时间

Get the initial expected test duration or end time of a Concurrency Thread Group at the beginning of the script

在 Jmeter 中,我使用 并发线程组 ${__tstFeedback(ThroughputShapingTimer,1,10,10)} 结合 吞吐量整形定时器 来动态改变整个测试期间的目标吞吐量。

我想要一个 JSR223 测试元素(断言或后处理器,重要吗?)在其中编写自定义逻辑以不记录某些特定错误但前提是它发生在测试脚本的结尾附近并且我不想硬编码时间值.

例如,如果我在计划的 运行 时间的最后 2 分钟内收到 java.net.SocketException,我不想记录它,但我确实想在其余时间记录它时间。 为此,我想我需要一些方法来获取自测试开始以来测试应该结束的日期,对其进行评估并从中减去 2 分钟,然后将当前时间与该时间进行比较,然后比较当前时间时间更长,然后开始执行一些逻辑以从日志记录中排除结果。

更新:在“正常”或“默认”线程组中,我注意到我可以这样做以获得初始持续时间:

String groupDuration = ctx.getThreadGroup().getDuration();
log.info(groupDuration)

但对于并发线程组,它的工作方式不同。

如果有任何信息可以帮助我实现这一目标,我将不胜感激。

您可以在使用 Filter Results Tool

测试后过滤结果

If you want to remove the ramp-up phase, you could use offset filters

使用--end-offset 120参数(秒)

对于dynamic thread groups和衍生品你可以使用以下函数:

ctx.getThreadGroup().getHold()

如果需要判断是分还是秒可以用

ctx.getThreadGroup().getUnitStr()

示例:

有关 JMeter 中 Groovy 脚本的更多信息:Apache Groovy - Why and How You Should Use It

如果您的 Concurrency Thread Group is configured with a Throughput Shaping Timer and Schedule Feedback Function the scheduled test duration is available through a property exposed 通过吞吐量整形计时器。

props.get('elementName_totalDuration')

The element will export the following propertyy that you can access through __P function or using in JSR223 Test Elements props.get("property name")

elementName_totalDuration - Total duration as sum of the "Duration,sec" column

elementName will be the name of your Throughput Shaping Timer

注意 您应该将 Hold Target Rate Time 设置为等于或大于吞吐量整形计时器计划中指定的总持续时间的值。因此,将此值设置为非常高的值以避免测试在吞吐量整形计时器中的预定持续时间之前完成。例如,设置目标保持率 t0 1440 分钟。

使用具有吞吐量整形计时器和反馈功能的并发线程组

When this thread group is used with Throughput Shaping Timer, you may replace Target Concurrency value with a call to the tstFeedback function to dynamically maintain thread count required to achieve target RPS. When using this approach, leave Concurrency Thread Group Ramp Up Time and Ramp-Up Steps Count fields blank, but be sure to set Hold Target Rate Time to a value equal or greater than the total Duration specified in the Throughput Shaping Timer schedule.