# Execute scenarios sequentially with different injection profiles

**URL:** <https://community.gatling.io/t/execute-scenarios-sequentially-with-different-injection-profiles/5097>\
**Category:** Gatling (Open-Source)\
**Created:** [June 27, 2019, 1:59am UTC](https://community.gatling.io/t/execute-scenarios-sequentially-with-different-injection-profiles/5097 "2019-06-27T01:59:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maria](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Maria](https://community.gatling.io/u/Maria)\
**Post date:** [June 27, 2019, 1:59am UTC](https://community.gatling.io/t/execute-scenarios-sequentially-with-different-injection-profiles/5097/1 "2019-06-27T01:59:57Z")

</div>

Hello. I need the advice on how to improve my scenario, I found the way of how to implement it though not sure that it is the best way to implement things.

I need to run N number of users within scenario 1 and when they finished, I want to trigger scenario 2 for only one user. Basically, for my system, it means that users publish N requests to the system and then we trigger the job which process all those requests. Afterwards, the system will generate N new events and I want to measure how long it takes to process all requests. I implemented it the following way though if there is any way to avoid doing the loop in scenario2 please share it with me.

```auto
class SettlementsSimulation extends Simulation {
  setUp(
    sendFundsRequestsScn.inject(
      constantUsersPerSec(2) during (2 seconds)
    ),
    triggerScriptScn.inject(
      atOnceUsers(1)
    )
  ).protocols(Settlements.jmsConfig, AutomationProperties.httpConf)
}

```

```auto

```

```auto
  lazy val sendFundsRequestsScn: ScenarioBuilder = scenario("Send Funds Requests")
    .feed(csv("cards.csv").circular)
    .feed(customFeeder)
    .exec(jms("SendMessage")
      .requestReply
      .queue(fromBoQueue)
      .replyQueue(toBoQueue)
      .textMessage(ElFileBody("FundsRequest.json"))
    )
    .exec { session =>
      fundsRequests = fundsRequests + 1
      session
    }

  lazy val triggerScriptScn: ScenarioBuilder = scenario("Trigger End-Of-Period script")
    .asLongAs(session => fundsRequests < 5) {
      doIf(session => fundsRequests == 4) {
        exec(
          http("Trigger End-Of-Period script")
            .post("/pmstatus")
            .body(StringBody("{\"command\": \"run\", \"parameters\": [\"settlement_ci\"]}"))
            .check(
              status.in(200)
            )
        )
      }
        .doIf(session => fundsRequests == 4) {
          exec { session =>
            fundsRequests = fundsRequests + 1
            println("Finishing scenario: " + fundsRequests)
            session
          }
        }
       // .exitHereIfFailed
        .pause(1 second)
    }

  var fundsRequests = 0

}

```

---

<div class="post-metadata">

**Author:** ![Ignacio\_Degeneffe](https://avatars.discourse-cdn.com/v4/letter/i/e0b2c6/32.png) [@Ignacio\_Degeneffe](https://community.gatling.io/u/Ignacio_Degeneffe)\
**Post date:** [June 27, 2019, 12:49pm UTC](https://community.gatling.io/t/execute-scenarios-sequentially-with-different-injection-profiles/5097/2 "2019-06-27T12:49:55Z")

</div>

maybe using rendezvous? [https://gatling.io/docs/2.3/general/scenario#rendezvous](https://gatling.io/docs/2.3/general/scenario#rendezvous)

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [June 27, 2019, 12:56pm UTC](https://community.gatling.io/t/execute-scenarios-sequentially-with-different-injection-profiles/5097/3 "2019-06-27T12:56:57Z")

</div>

Please use up-to-date links, eg [https://gatling.io/docs/current/general/scenario/#rendezvous](https://gatling.io/docs/current/general/scenario/#rendezvous)

Gatling 2 is no longer maintained.

---

<div class="post-metadata">

**Author:** ![Maria](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Maria](https://community.gatling.io/u/Maria)\
**Post date:** [June 28, 2019, 2:17am UTC](https://community.gatling.io/t/execute-scenarios-sequentially-with-different-injection-profiles/5097/4 "2019-06-28T02:17:35Z")

</div>

I tried RendezVous but it stops all X users in scenario1 and then they all execute scenario2 while I want it to be done only once. I spent some more time and improved the loop in scenario2. I didn’t find any other way of implementing this test. It would be nice to have a feature allowing to define the sequence of scenarios in setUp() block

```auto

var continue: Boolean = true
lazy val triggerScriptScn: ScenarioBuilder = scenario("Trigger End-Of-Period script")
  .asLongAs(session => continue) {
    doIf(session => fundsRequests == 4) {
      exec(
        http("Trigger End-Of-Period script")
          .post("/pmstatus")
          .body(StringBody("{\"command\": \"run\", \"parameters\": [\"settlement_ci\"]}"))
          .check(
            status.in(200)
          )
      )
        .exec { session =>
          continue = false
          println("Finishing scenario, processed FR: " + fundsRequests)
          val sqs: SQSConsumer = new SQSConsumer

```
