0
votes

I'm pretty new at Scala/Gatling so forgive me if you see an anti-pattern or something wrong, I have a Gatling scenario in which I have to run some bash external scripts, and have to save some variables for their use in another exec block (I've tried calling the .exec right after the " exec(session => { ..." block, and have tried calling it as a method in another object.

 exec(session => {
            val scriptOutput = s"src/main/resources/thepath/myscript.sh ${arg1} ${arg2}".!!
            val x_variable = "123" + scriptOutput
            session.set("x_variable",x_variable)
        })
        .exec(MyClient.calling)

In "MyClient", I need to use the value of "x_variable", I currently have something like this:

    def calling() = {
        exec(http("POST to ${x_variable}")
                .post("/${x_variable}"))
    }

But when doing so, it doesn't work, the Post call is made but the variable "x_variable" is empty. To summarize, the question is how to pass that "session" information to any next "exec" block (right after or in another object), and how to consume it from that "session"?

1
Your code should work. Do you have the error logs?George Leung
That's the weirdest part, there is no error in the logs, rather than the one after the execution finishes (I have an assertion about the error rate, and all tests finished with 100% KO) I can see the bash script output in the log while the injection is active, and the post is made, the problem is still the mentioned, the x_variable is empty (It does not take the value passed from the previous block)Cristian Moyano
Have you turned on the logging?George Leung
Yeah, it seems I had something wrong with the environment. Effectively, as you mentioned the code is working as expectedCristian Moyano

1 Answers

0
votes

The code described is working now, it seems I had some "trash" in the environment, after doing an mvn clean install it worked as expected.