# Test Case Duration in Gatling

**URL:** <https://community.gatling.io/t/test-case-duration-in-gatling/8251>\
**Category:** Gatling (Open-Source)\
**Created:** [August 29, 2023, 11:10am UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251 "2023-08-29T11:10:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![sachinpadha](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@sachinpadha](https://community.gatling.io/u/sachinpadha)\
**Post date:** [August 29, 2023, 11:10am UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/1 "2023-08-29T11:10:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GatlingPete](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/gatlingpete/32/1167_2.png) [@GatlingPete](https://community.gatling.io/u/GatlingPete)\
**Post date:** [August 29, 2023, 12:58pm UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/2 "2023-08-29T12:58:26Z")

</div>

Hello,

Have you checked the documentation on loops?

> **[Scenario](https://gatling.io/docs/gatling/reference/current/core/scenario/#loop-statements)**
>
> How to define scenarios that your virtual users will execute. Use exec to attach a chain or execute a request or a function. Use loops such as repeat, during and asLongAs. Use conditions like doIf and randomSwitch. Uses pauses.

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

> **[Injection](https://gatling.io/docs/gatling/reference/current/core/injection/)**
>
> How to define the way virtual users are started over time and injected into a scenario. Explain the difference between open and closed workload models and which type suites best your application.

Best,  
Pete

---

<div class="post-metadata">

**Author:** ![sachinpadha](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@sachinpadha](https://community.gatling.io/u/sachinpadha)\
**Post date:** [September 4, 2023, 4:32pm UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/3 "2023-09-04T16:32:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![GatlingPete](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/gatlingpete/32/1167_2.png) [@GatlingPete](https://community.gatling.io/u/GatlingPete)\
**Post date:** [September 6, 2023, 1:48pm UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/4 "2023-09-06T13:48:13Z")

</div>

Yes, that’s correct.

---

<div class="post-metadata">

**Author:** ![sachinpadha](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@sachinpadha](https://community.gatling.io/u/sachinpadha)\
**Post date:** [September 21, 2023, 1:26pm UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/5 "2023-09-21T13:26:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GatlingPete](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/gatlingpete/32/1167_2.png) [@GatlingPete](https://community.gatling.io/u/GatlingPete)\
**Post date:** [September 21, 2023, 2:26pm UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/6 "2023-09-21T14:26:17Z")

</div>

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

EG:

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

```

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [September 21, 2023, 2:51pm UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/7 "2023-09-21T14:51:39Z")

</div>

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](https://gatling.io/docs/gatling/reference/current/core/scenario/#during) an amount of time.

```java
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!

---

<div class="post-metadata">

**Author:** ![sachinpadha](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@sachinpadha](https://community.gatling.io/u/sachinpadha)\
**Post date:** [September 21, 2023, 4:00pm UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/8 "2023-09-21T16:00:29Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![sachinpadha](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@sachinpadha](https://community.gatling.io/u/sachinpadha)\
**Post date:** [September 27, 2023, 3:05am UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/10 "2023-09-27T03:05:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [September 27, 2023, 6:55am UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/11 "2023-09-27T06:55:43Z")

</div>

Hi @sachinpadha,

> [@sachinpadha](#):
>
> ```auto
> setUp(scn.injectOpen(constantUsersPerSec(2).during(30))).protocols(httpProtocol);
> 
> ```

> [@sachinpadha](#):
>
> That means each second 2 user sessions will be created?

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

> [@sachinpadha](#):
>
> So at 5th second, there will be 10 active users, at 7th second 14 active users?

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.

> [@sachinpadha](#):
>
> That means, it is trying to delete the same ID which I already deleted during the generation of HAR file?

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!

---

<div class="post-metadata">

**Author:** ![sachinpadha](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@sachinpadha](https://community.gatling.io/u/sachinpadha)\
**Post date:** [September 27, 2023, 7:35am UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/12 "2023-09-27T07:35:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [September 27, 2023, 7:48am UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/13 "2023-09-27T07:48:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sachinpadha](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@sachinpadha](https://community.gatling.io/u/sachinpadha)\
**Post date:** [September 27, 2023, 7:58am UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/14 "2023-09-27T07:58:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [September 27, 2023, 8:09am UTC](https://community.gatling.io/t/test-case-duration-in-gatling/8251/15 "2023-09-27T08:09:13Z")

</div>


