dynamic number of users for scenario

Hi,
I am doing a scenario in Gatling that should execute as follows

  • Create a resource (should be executed only once)
  • Add items to the resource (10K items that need to execute in parallel (10 concurrent users))
  • Delete the resource (should execute only once)

I see that the scenario should have a static number of users, and if I created two scenarios they will be executed in parallel which will cause some of the requests to fail due to the execution order dependencies

Is there a solution to solve this issue ?

Thanks

I am using gatling 2.3, but it is OK to update if there is a solution in a higher version

I don’t know of an “easy” way of doing this, but one thing you can do is code your scenario to do the whole process, but add logic so that only the first virtual user does the creation and deletion, and the rest all wait for it.

This means setting a flag in the session to indicate if the current virtual user is the first one or not. I’m not sure if there is a session variable to indicate which virtual user the current one is. If such a value exists, you can inspect that. If that does not exist, you can accomplish the desired goal manually with something like this:

(caveat: untested code):

object isFirstUser {
private Boolean initialized = false
synchronized def apply() = {
if ( ! initialized ) {
initialized = true;
return true;
} else {
return false;
}
}
}

Now, you code the rest of the scenario something like this (pseudo-code):

.exec( _.set( “FIRST_USER”, isFirstUser() ) )
.doIf( _(“FIRST_USER”).as[Boolean] ) { /* create / }
.rhondesvouse( Test.users ) // wait for the first one to complete
.repeat( Total / Test.users )
feed( item to add )
.exec( add item to resource )
}
.rhondesvouse( Test.users ) // let them all finish
.doIf( _(“FIRST_USER”).as[Boolean] ) { /
delete */ }

That make sense?