Gatling pause function usage - before or/And after exec

Anyone,
What is the current way to introduce pause before & after a request.
Below is how I have written the code but I am sure it doesn’t work as expected. I am expecting the requests to be 4s apart. See the diagram at bottom:
If I place pause inside exec code block, I get errors:

Desktop/gatling-charts-highcharts-bundle-2.2.3/user-files/simulations/computerdatabase/simulation.scala:47: value http is not a member of io.gatling.core.structure.ChainBuilder
possible cause: maybe a semicolon is missing before `value http’?
16:35:23.284 [ERROR] i.g.c.ZincCompiler$ - http(requestName)
16:35:23.285 [ERROR] i.g.c.ZincCompiler$ - ^
16:35:23.285 [ERROR] i.g.c.ZincCompiler$ - /Users/z0019cb/Desktop/gatling-charts-highcharts-bundle-2.2.3/user-files/simulations/computerdatabase/simulation.scala:48: type mismatch;
found : String("${url}")
required: Int

val scn = scenario(scenarioName)
.feed(csvFeeder)
.pause(2 seconds)
.during(testTimeSecs) {
exec(
http(requestName)
.get("${url}")
.headers(http_headers)
)
.pause(2 seconds)
}

Base on the code you posted, you are waiting 2s before the “during” loop start and 2s after each request in the loop.

If you want to wait 2s before each request present in the loop, move the first “.pause(2 seconds)” inside the loop:

`
val scn = scenario(scenarioName)
.feed(csvFeeder)
.during(testTimeSecs) {
pause(2 seconds)

.exec(
http(requestName)
.get("${url}")
.headers(http_headers)
)
.pause(2 seconds)
}
`

Thanks a lot Stephen, much appreciated.

Hi, I need one more clarification, I have used convert function to change the type of parameter “reltime” from string to int. This value I am trying to pass to pause function & it works. But I want to do mathematical operation on this “reltime”; something like below

val pauseduration = “${reltime}” - (System.currentTimeMillis / 1000 - teststarttime)

here teststarttime is constant.

Error = 12:50:45.219 [ERROR] i.g.c.ZincCompiler$ - /Users/******/Desktop/gatling-charts-highcharts-bundle-2.2.3/user-files/simulations/computerdatabase/sample_simulation.scala:43: value - is not a member of String

val csvFeeder = csv(“test.csv”)
.queue
.convert{case (“reltime”, string) => string.toInt}

I’m not sure you can do whant you want that way.

"${reltime}" is a String, that is why you get the error.

Since you get reltime from a feeder, you can retrieve the variable using the user session :

val reltime = session(“reltime”).as[Int]

Then you can do the math with that int variable :

val pauseduration = reltime - (System.currentTimeMillis / 1000 - teststarttime)

Thanks Stephen,
but I am not sure I am doing the session thing right as I am getting not found: value session error while running.
Below is my full code:

val scn = scenario(scenarioName)
.feed(csvFeeder)
val reltime = session(“reltime”).as[Int]
val pauseduration = reltime - (System.currentTimeMillis / 1000 - teststarttime)
.pause(pauseduration)
.during(testTimeSecs) {
exec(
http(requestName)
.get("${url}")
.headers(http_headers)
)

}