Hi, I just involved the new project for load test for our service by using Gatling, below is my first program for it.
class BasicSimulation extends Simulation {
val xApiKey = “xxxxx”
val topic = “load-test_gatling_4000_2000”
var accessToken : String = “xxxxxx”
var topic_base = “Gatling_LoadTest_”
var topic_count = 50
val httpDefaults = http.baseURL(“https://url_of_my_serivce/v1/api”)
object PublishMessageAPI {
val headers = Map(
“Accept” → “application/json”,
“Content-Type” → “application/json”,
“Authorization” → “Bearer ${accessToken}”)
val publish = foreach("${topics}", “topic”) {
var topic : String = “${topic}”
exec(http(“pub”)
.post("/pub")
.headers(headers)
.header(“X-Api-Key”, s"$xApiKey")
.header(“X-Hool-Parameters”, s"event; topic=$topic; partition=0")
.check(status.in(200,204)))
}
var topicList:ListBuffer[String] = ListBufferString
def prePareTopics(session:Session): Session = {
for (i ← 1 to topic_count) {
topicList += (topic_base + i)
}
session.set(“topics”, topicList)
return session
}
}
val test = scenario(“Load Test”)
.exec{session =>
session.set(“accessToken”, accessToken)
PublishMessageAPI.prePareTopics(session)
}
.during(5 minutes) {
exec(PublishMessageAPI.publish)
.exitHereIfFailed
.pause(0 milliseconds, 100 milliseconds)
}
setUp(
test.inject(
nothingFor(5 seconds), atOnceUsers(2000)
).throttle(reachRps(5000) in (50 seconds), holdFor(10 minute))
).assertions(
global.successfulRequests.percent.greaterThan(95)
).protocols(httpDefaults)
When I run this test, I always got [ERROR] i.g.c.s.LoopBlock$ - Condition evaluation crashed with message ‘No attribute named ‘topics’ is defined’, exiting loop
Maybe the “accessToken” has the same issue. Where should I set the “topics” to session?
Thanks!