I am updating some performance tests that use Gatling to test the performance when a user creates an assignment with several classes in it rather than just one class which is what we test currently.
I'm entirely new to Scala and Gatling but I have managed to figure out, I think, almost everything. I just have one spot that is causing problems and perplexing the dickens out of me.
The following bit of code grabs all students that are in a given class (we call them sections). This is the existing code that works exactly as expected with the existing tests, yet for some reason the new tests always throw an error that listOfStudents
doesn't exist.
The error to throws is 'hook-81' crashed with 'java.util.NoSuchElementException: key not found: listOfStudents', forwarding to the next one
val getListOfStudents = http("Get list of students")
.get(BASE_URL + "/v2/sections/${sectionRefId}/rosters")
.headers(getHeaderMap)
.check(status.is(Ok),
jsonPath("$.students[*].refId").findAll.transform(_.mkString(",")).saveAs("listOfStudents"))
I found this question, Gatling not storing value in session, that talks about session being immutable but I don't think I have any spots that would generate a new session except at the end of blocks so it shouldn't be the issue.
The original tests uses the following code to grab the list of students and the value is properly saved in this scenario:
val createEdCtsAssignment = repeat(4) {
exec(getTeacherSectionId)
.exec(getListOfStudents)
.exec(session => session.set("assignmentType", "PROGRAM_ASSESSMENT"))
.exec(createTeacherAssignment)
}
This is the code where it doesn't work:
val createMultiSectionEdCtsAssignment = repeat(2) {
exec(getTeacherMultiSectionSectionId)
.exec(session => session.set("listOfStudentsBySection", ""))
.foreach(session => session("listOfSectionRefIds").as[String].split(',').toSeq, "sectionRefId") {
exec(session => {
exec(getListOfStudents)
session.set("listOfStudentsBySection", collectStudents(session))
})
}
.exec(session => session.set("assignmentType", "PROGRAM_ASSESSMENT"))
.exec(createMultiSectionTeacherAssignment)
}
After adding lots of println()
s I found the error happens in session.set("listOfStudentsBySection", collectStudents(session))
. In collectStudents
the failure happens at val studentsList = session("listOfStudents").as[String]
. This is the exact same line of code that works when called in createTeacherAssignment
. Both of those functions exist in their own files but even trying to print the value of listOfStudents
right after exec(getListOfStudents)
generates the same error.
The only real change between them is the presence of the foreach
loop in the non-working version.
(Our Gatling version is 2.2.5)
I have tried everything I can find or think of with no success. Does anyone have any ideas?
exec(session => {
exec(getListOfStudents)
session.set("listOfStudentsBySection", collectStudents(session))
})
This is completely wrong. As explained in the documentation, you're creating a building that doesn't do anything.
This is correct:
exec(getListOfStudents)
.exec { session =>
session.set("listOfStudentsBySection", collectStudents(session))
}
Then, Gatling 2 has been DEAD for year! Please upgrade for a modern version. The current version is 3.6.1 and 3.7.0 will be out in a few weeks.