Hello,
I’ve already done my research and it seems there’s no way to break out of a Gatling foreach() loop. I’m looking for direction on how to implement this appropriately in Gatling EL.
My objective
I’d like to run a foreach() loop over a Map of Clients (json results), and break out of the foreach loop once it finds a client who has Documents, and iterate over the “allClients” array until it does find a client with documents.
The problem:
The foreach(“allClients”) loop keeps on running, and moving onto the next client, and the asLongAs() condition is never checked. I need to stop the foreach(“allClients”) once it hits a client with documents, and thus asLongAs() condition fails and stops.
Pseudocode
The code below is conceptually how my code works.
asLongAs(session.contains(“clientFoundWithDocuments”) == false) {
foreach(“allClients”, “clientId”) {
var allDocuments = get("/get/documents/{$clientId}")
if(allDocuments.size > 0) {
session.set(“clientFoundWithDocuments”, “true”) ←
foreach(“allDocuments”, as “documentId”) {
get("/get/document/${documentId}")
}
}
}
}
Actual code:
https://gist.github.com/dragoonis/9f89a6f842a07b9799ac480c2a992c84
Many thanks,
Paul