Adding a POST before every GET

I am trying to load test a site that has some strange behaviour. Before every page load, there is POST to a tracking URL. So every page load is a POST followed by a GET. Now I could manually add this POST every time there is a GET, which would result in a lot of duplication of code. Is there a cleaner way to trigger the POSTs?

Thanks

Mark

Kinda. You could minimize the redundancy like this:

`
val tracking = http( “tracking” ).post( url ).silent

val scn = scenario(“name”)
.exec( … ).exec( tracking )
.exec( … ).exec( tracking )

`

You could go further, if you really wanted to, such as (only will work on 2.2 - not guaranteed to be 100% correct):

`
import io.gatling.core.structure.HttpRequestBuilder
import io.gatling.core.structure.ChainBuilder
def tracked( request : HttpRequestBuilder ) : ChainBuilder = exec( request ).exec( http( “tracking” ).post( url ).silent )

val scn = scenario(“name”)
.exec( tracked( … ) )
.exec( tracked( … ) )

`

But if you do that, are you actually creating shorter or more readable code or not? My vote on that is, no, not really.

Well, I personally do this exact kind of factory when dealing with CORS.

Is 2.2 stable? The latest release on the website is 2.1.7. I do prefer your second option, but if I used the first option, is there an easy way to make the tracking configurable. i.e. so that I could easily run the load test with and without the tracking just by changing a simple config value. Sorry my knowledge of Scala is practically zero.

Thanks for the help John.

Mark

No, 2.2 is not stable yet, those are milestones. They are usable, but not documented, and internals are subject to changes until 2.2.0 is out.

Pass a system property, and do a if your def.