No attribute named 'topics' is defined

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}”
.header(“X-Api-Key”, s"$xApiKey")
.header(“X-Hool-Parameters”, s"event; topic=$topic; partition=0")

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)
.during(5 minutes) {
.pause(0 milliseconds, 100 milliseconds)

nothingFor(5 seconds), atOnceUsers(2000)
).throttle(reachRps(5000) in (50 seconds), holdFor(10 minute))

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?


Your only concern should be around the session, which is immutable:

Thanks for the help Guillaume, it works!