Dynamically adding scenarios based on loop

It is possible to loop the Scenario injection like below:-

setUp(
    (1 to 3).flatMap(i => Seq(
    matchScenario.inject(
      rampConcurrentUsers(1) to t_concurrency during t_rampUp,
      constantConcurrentUsers(t_concurrency) during t_holdFor,
      rampConcurrentUsers(t_concurrency) to 1 during t_rampUp
    )))).protocols(httpConf)
  ).maxDuration(t_holdFor + 2*t_rampUp) //stop the test after maxDuration time is completed

}

Hi @selva4 ,

Please, help us to help you.

  1. What do you want to achieve?
  2. What is your question?
  3. When providing code snippet, please provide the smallest code snippet that is actually useful (we need to guess what mean your own values)

Cheers!

Hi @sbrevet

we have a list of API’s and each API is assigned to a scenario builder,

what we are trying is here,

for example let’s say 5 API we have, created the corresponding 5 scenario builder, we have a jenkins UI which list out all API’s name in checkbox format based on User selection,
let’s say 2 API’s only selected this time in checkbox, so two scenario injection have to be created with the help of loop.

below one i can use it, but it will run always 5 injection profile every time, based on user selection injection profile count will vary so can i loop it the injection profile.

User selection 1 to 5 every time. how to automate it?

setUp(
      scnLaunchApp.inject(rampUsers(Integer2int(Integer.getInteger("users",200))) over (60 minutes),
          constantUsersPerSec(200) during(12 hours)),
      scniosDeviceApps.inject(rampUsers(Integer.getInteger("users",200)) over (60 minutes),
          constantUsersPerSec(200) during(12 hours)),
      scnBrowseAndInstallApp.inject(rampUsers(Integer.getInteger("users", 200)) over (60 minutes),
          constantUsersPerSec(200) during(12 hours)),
      scnForcedHeartBeat.inject(rampUsers(Integer.getInteger("users", 200)) over (60 minutes),
          constantUsersPerSec(200) during(12 hours)),
      scnDownloadMCM.inject(rampUsers(Integer.getInteger("users", 200))over (60 minutes),
          constantUsersPerSec(200) during(12 hours))
      ).protocols(EMMPerfConfig.httpConf)

Please let me know if you need more clarifications


Jenkins UI

Obviously, we won’t help with your jenkins part.

To reduce verbosity (as I don’t think that is the subject at hand), let’s start with this code:

class Sample extends Simulation {
  private val httpProtocol = http
    .baseUrl("https://sample.com")

  val scnLaunchApp = scenario("LaunchApp").exec(
    // ...
  )
  val scniosDeviceApps = scenario("iosDeviceApps").exec(
    // ...
  )

  setUp(
      scnLaunchApp.inject(atOnceUsers(1)),
      scniosDeviceApps.inject(atOnceUsers(1)),
    ).protocols(httpProtocol)
}

Do you know that setUp may take a List[PopulationBuilder] as arguments?

  val injections = List(
    scnLaunchApp.inject(atOnceUsers(1)),
    scniosDeviceApps.inject(atOnceUsers(1)),
  )

  setUp(injections).protocols(httpProtocol)

Do you know that you can build a list of elements that are optional?

val sample = List(
  Some(1),
  None,
  Some(2),
  None,
  None,
  Some(3)
)
// val sample: List[Option[Int]] = List(Some(1), None, Some(2), None, None, Some(3))

Then, you can flatten it

sample.flatten
// res: List[Int] = List(1, 2, 3)

In another hand, you can get an option for an environment variable with sys.env.get("ENV_NAME") or an option of system property with sys.props.get("prop.name").

So, you can write something like:

  val injections = List(
    sys.props.get("launchApp").filter(_ == "true").map(_ => scnLaunchApp.inject(atOnceUsers(1))),
    sys.props.get("iosDeviceApps").filter(_ == "true").map(_ => scniosDeviceApps.inject(atOnceUsers(1))),
  ).flatten

  setUp(injections).protocols(httpProtocol)

To achieve what you want.

Is that clear?

I (really do) hope that helps.

Cheers!

Thanks @sbrevet, it seems exactly what i am looking, let me try and will know about this