Test Case Duration in Gatling

Suppose, I have given 50 numbers of users which are going to use the application during the Gatling tool Testing. That means 50 users load on the website. I want these 50 users to keep hitting the website for an hour continuously. Means, if one user performs 4 tasks (Add, update, delete, search ) then it should not stop after the completion of task but should keep doing the same task for an hour or two hours. Is there any parameter where we can set the duration so that the workload keeps hitting the website for such a long duration? Also all these users hit website simultaneously at the same time? I have checked docs but didn’t get the parameter where we can set the duration.

Hello,

Have you checked the documentation on loops?

Also regarding the duration of the test, this is set in the injection profile:

Best,
Pete

Hi Pete,

I go through the document and for my requirement during will be fitted perfectly. That will give the duration of seconds the loop will iterate for that particular duration. Is my understanding correct? If yes, then I need to use during in each scenario? I have sent the java file via email and in that I need to replace ‘pause’ with ‘during’ to cater my requirement, Is my understanding correct?

Yes, that’s correct.

Hi Pete, I have sent you the modified java file via email. When I replaced pause with during, I got error while executing gatling.bat. Below is the error:

Type the number corresponding to your choice and press enter
[0]
[1] Run the Simulation locally
[2] Package and upload the Simulation to Gatling Enterprise Cloud, and run it there
[3] Package the Simulation for Gatling Enterprise
[4] Show help and exit
1
18:53:24.310 [ERROR] i.g.c.ZincCompiler$ - C:/D_Drive/gatling/source/user-files/simulations/apexdel/BasicSimulationApexDelete.java:113:1: illegal start of expression
18:53:24.315 [ERROR] i.g.c.ZincCompiler$ - C:/D_Drive/gatling/source/user-files/simulations/apexdel/BasicSimulationApexDelete.java:194:1: ‘;’ expected
18:53:24.316 [ERROR] i.g.c.ZincCompiler$ - C:/D_Drive/gatling/source/user-files/simulations/apexdel/BasicSimulationApexDelete.java:195:1: illegal start of expression
18:53:24.317 [ERROR] i.g.c.ZincCompiler$ - C:/D_Drive/gatling/source/user-files/simulations/apexdel/BasicSimulationApexDelete.java:195:1: invalid method declaration; return type required
18:53:24.317 [ERROR] i.g.c.ZincCompiler$ - C:/D_Drive/gatling/source/user-files/simulations/apexdel/BasicSimulationApexDelete.java:195:1: illegal start of type
18:53:24.319 [ERROR] i.g.c.ZincCompiler$ - C:/D_Drive/gatling/source/user-files/simulations/apexdel/BasicSimulationApexDelete.java:206:1: illegal start of type
18:53:24.321 [ERROR] i.g.c.ZincCompiler$ - C:/D_Drive/gatling/source/user-files/simulations/apexdel/BasicSimulationApexDelete.java:206:1: invalid method declaration; return type required
18:53:24.321 [ERROR] i.g.c.ZincCompiler$ - C:/D_Drive/gatling/source/user-files/simulations/apexdel/BasicSimulationApexDelete.java:206:1: illegal start of type
18:53:24.322 [ERROR] i.g.c.ZincCompiler$ - C:/D_Drive/gatling/source/user-files/simulations/apexdel/BasicSimulationApexDelete.java:217:1: illegal start of type
18:53:24.323 [ERROR] i.g.c.ZincCompiler$ - C:/D_Drive/gatling/source/user-files/simulations/apexdel/BasicSimulationApexDelete.java:217:1: invalid method declaration; return type required
18:53:24.325 [ERROR] i.g.c.ZincCompiler$ - C:/D_Drive/gatling/source/user-files/simulations/apexdel/BasicSimulationApexDelete.java:217:1: illegal start of type

Apologies, I misunderstood your previous point. Your duration only needs to be in the injection block, not replacing the pauses.

EG:

    setUp(
      scn.injectOpen(constantUsersPerSec(10).during(300))
    ).protocols(httpProtocol);

Hi @sachinpadha,

If I understand, you have 4 steps (Add, update, delete, search).

What each user should (ie, a scenario) is to perform such task in a loop during an amount of time.

ScenarioBuilder scn = scenario("My scenario")
  .exec(userInit)
  .during(Duration.ofHours(1)).on(
    exec(add, update, delete, search)
  );

{
  setUp(scn.injectOpen(atOnceUsers(50))).protocols(httpProtocol);
}

Does that help?

Cheers!

In the attached java file the below code is throwing an error:

//setUp(scn.injectOpen(atOnceUsers(1))).protocols(httpProtocol);
setUp(scn.injectOpen(atOnceUsers(10))).protocols(httpProtocol);

21:29:46.729 [ERROR] i.g.c.ZincCompiler$ - Compilation crashed
sbt.internal.inc.CompileFailed: null
at sbt.internal.inc.javac.AnalyzingJavaCompiler.$anonfun$compile$12(AnalyzingJavaCompiler.scala:179)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at sbt.internal.inc.javac.AnalyzingJavaCompiler.timed(AnalyzingJavaCompiler.scala:262)
at sbt.internal.inc.javac.AnalyzingJavaCompiler.compile(AnalyzingJavaCompiler.scala:161)
at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$2(MixedAnalyzingCompiler.scala:103)
at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$2$adapted(MixedAnalyzingCompiler.scala:91)
at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$1(MixedAnalyzingCompiler.scala:91)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
at sbt.internal.inc.MixedAnalyzingCompiler.compileJava(MixedAnalyzingCompiler.scala:61)
at sbt.internal.inc.MixedAnalyzingCompiler.compileJava0$1(MixedAnalyzingCompiler.scala:198)
at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
at sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:179)
at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:177)

I have corrected the basic mistakes and with below code, I am able to execute the Gatling. I have attached the java file

setUp(scn.injectOpen(constantUsersPerSec(2).during(30))).protocols(httpProtocol);

My question is: In this 2 active users will be there for a second. That means each second 2 user sessions will be created? So at 5th second, there will be 10 active users, at 7th second 14 active users? Is it per request user or over all user?

Also in my Gatling test case, I am deleting a few records from the Database and got recording in the HAR file. But then Gatling test cases got executed for 30 seconds, none of the records got deleted? The count remained the same? That means, it is trying to delete the same ID which I already deleted during the generation of HAR file?

Hi @sachinpadha,

Correct, each second, 2 new virtual users will be injected.

5th second, 9th and 10th users will be injected.
7th second, 13th and 14th users will be injected.
But depending on the virtual users injected before already have finished their scenario or not, it won’t match with the active users count.

If you didn’t change the request, I guess it is always the same endpoint with the same params that are called. There is no IA in the recorder that can understand your usage, you will have to change it in order to make sense of the simulation.

I guess the original post is now fully covered.
If you agree, let’s mark this one as resolved (and point to the solution).

For other questions, please open a new topic for each one.

Cheers!

setUp(scn.injectOpen(constantUsersPerSec(2).during(30))).protocols(httpProtocol);

This also means that the entire Gatling script will be executed for 30 seconds and If I replace the during(30) with during(3600) that means it will execute for 1 hrs and MAX users will injected = 7200… Am I right?

It means that the last users will be injected at the 30th second.
The simulation will terminate when all users ended their scenario.
3600seconds x 2 users/second = 7200 users, indeed.

Cool. We can close this topic. Let me open NEW topic about the IDs (end point change)