check.expect or check.until with dynamic values

Hello,

I’ve been working with gatling 2.2.2 and it is great. I was able to get almost everything I wanted accomplished with it, now I’m going for an extra goal and trying to use a dynamic number for the number of messages on an sse stream check:

.exec(sse("Set check for ${num} events")
  .check(wsListen.within(GlobalObj.testRunTime())
    .until(1)))

works as long as the until is an integer, but if i use a variable:

.exec(sse("Set check for ${num} events")
  .check(wsListen.within(GlobalObj.testRunTime())
    .until(GlobalObj.testNumberOFMessages())))

this always fails the check when the simulation is over. I’m assuming because gatling runs precompiled simulation classes, in which it will fail due to the var not being set during compilation. Is this true, and if it is, is there a way to work around it? I tried marking both the testNumberOfMessages val and the scenario val as lazy, and still the same issue.

I’ve also tried pulling the ${num} out the session with

.exec( session => {  
  sse("Set check for ${num} events")
     .check(wsListen.within(GlobalObj.testRunTime())
       .until(session("num").validate[Int].get)))  
  session
  }
)

but this causes the check to not run?

Currently, the “until” method takes a static Int.

Thanks Stephane, are there any plans to address this, possibly with the web socket api rewrite you’ve mentioned? If not I’d be happy to fork and try to put in the feature myself.

Thanks Stephane, are there any plans to address this, possibly with the
web socket api rewrite you've mentioned?

Maybe, if it makes sense :slight_smile:
Could you please explain your use case?

If not I'd be happy to fork and try to put in the feature myself.

Sure, go ahead.

Thanks Stephane, are there any plans to address this, possibly with the web socket api rewrite you’ve mentioned?

Maybe, if it makes sense :slight_smile:
Could you please explain your use case?

I’m using gatling as a library and dynamic test framework, by calling the Gatling.fromArgs, and passing in the compiled simulation class directory using reflection. It seems to me as if it was designed to run as its own application, which is fine but not in line with what I was looking for. I have an http server that current serves a /startTest route, and takes in different parameters for the test: reconnections, number of streams to open (gatling users), etc. All of these parameters except the numberOfEventsPerStream work by the server parsing the http response, pulling out the params, putting them in the user’s session.I can pull the number of out of the session during the simulation, but storing it in a var and passing that into the .until method doesn’t work as mentioned before.

Basically since the object generating the streaming events is decoupled from the gatling test (not a standard gatling test pattern from what I’ve gathered), I have no way of knowing at compilation time of the gatling test app what the number of events for each stream is. This changes depending on the event generation pattern and how long the generator is run for. I do know how many events per stream when I kick off a test, as it will always be after starting the generator with known parameters.

If not I’d be happy to fork and try to put in the feature myself.

Sure, go ahead.

I’ll definitely check out the code to see if there’s something quick that I can do, will send a PR if I find something clean and easy. Just to make sure, is there an easier way to run simulation classes directly? That would also be a potential workaround to this issue, something like scenario.run().

I

Mmm, so that’s definitively not a standard use case / supported usage.

Usually, in order to pass such data to the simulation, you would set System properties.
It only makes sense to store data in the Sessions if it is supposed to be different from one user to another.
But it’s not the case. You’re just trying to use that as a workaround.