scala - 如何按顺序而不是同时运行加特林场景?
问题描述
我创建了一个简单的 gatling maven 应用程序来测试性能,验证 API 速率限制(因此,如果发送的请求超过其速率限制,它应该会失败)。为了将每个 api 作为独立操作而不是同时运行,我为每个 API 调用创建了单独的模拟类以进行测试。为了按顺序运行它们,我启用了 runMultipleSimulations 。遵循例如配置:galting doc:https ://gatling.io/docs/3.0/extensions/maven_plugin/
但我不认为它们是按顺序运行的,我从日志中看到的一种情况主要是显示失败的用户请求和 500 个内部服务器错误,我也没有在日志中看到所有测试场景。除了这个依赖,我还需要其他什么吗?这是我的 pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gatling-test</groupId>
<artifactId>gatling-test</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<gatling-plugin.version>3.0.1</gatling-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>3.1.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling-plugin.version}</version>
<configuration>
<runMultipleSimulations>true</runMultipleSimulations>
</configuration>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
例如:一个场景文件:
class DeleteAPISimulation extends Simulation {
var test = ""
val preScenario = scenario(" DELETE API PRE-SCENARIO")
.exec(CreateResource())
.exec(session => {
test = session("resourceId").as[String].trim
println("%%%%%%%%%%% resource ID =====>>>>>>>>>> " + test)
session}
)
val deleteResourceScenario = scenario("DELETE API TEST SCENARIO")
// Set it here
.exec(_.set("resourceId", test))
.exec(DeleteResource())
setUp(
preScenario.inject(atOnceUsers(1)),
deleteResourceScenario.inject(rampUsers(520) during(60))
)
}
Actions 类具有 API 的 DSL http 请求实现。例如:
object Actions{
def DeleteResource():HttpRequestBuilder = {
http("DELETE_RESOURCE_OPERATION")
.delete(Host+ "/items/${resourceId}")
.header("Authorization", "Bearer "+ Token)
.check(status.is(200))
}
.
.
//so on
// similar api method requests
.
}
下面是我的项目结构的外观和动作类以及场景模拟类位于 src/test/scala 下:
gatlingtest
- src
- test
- resources
- scala
- Actions
- CreateAPISimulation
- GetAPISimulation
- DeleteAPISimulation
解决方案
从 Gatling 3.3 开始,没有真正的方法可以按顺序运行场景。唯一的解决方案是在延迟一段时间后启动其他场景,见nothingFor。
Gatling 3.4 (2020 年 9 月发布)中将引入顺序场景。
推荐阅读
- ansible - 收集事实时出现 Ansible 致命错误,“module_stderr”:“共享连接已关闭
- ruby-on-rails - Rails 6 悲观锁与 jsonb
- c# - 我在使用统一制作的游戏中有一种滞后,这与地面检查有关
- java - 递归插入排序
- system-verilog - 一个 IMP_PORT 连接到多个 EXPORTS
- swift - 是否可以快速划分两个数字?
- google-sheets - 从一列到跨多列的限制行长度的唯一列表 Google 表格
- html - 如何使字体大小与其在css中的输入高度成比例?
- javascript - WebRTC 将 AudioContext 中的音频添加到 captureStream
- azure-devops - MagicChunks 不写 web.config 属性