Random ChainBuilder for each cycle inside .forever loop

51 views
Skip to first unread message

Eugene Abramchuk

unread,
Apr 27, 2017, 9:48:05 AM4/27/17
to Gatling User Group
Hi guys. I am executing a scenario where I need to continuously fire up weighed random actions, the same thing that 
.randomSwitch()
does. The only problem is that randomSwitch cannot operate inside the forever loop and this is exactly where I need it to be.

I tried to circumvent this by adding an own Scala value with own random distribution, but that does not seem to be evaluated during runtime. Any ideas? Maybe it was a bad choice of course in the first place.

My code follows:

class EFT extends BaseScenario {

  def r = new scala.util.Random

  override def scenarioBuilder = scenario(getClass.getSimpleName)
    .exec(Account.create)
    .exec(Account.login)
    .exec(Account.activate)
    .exec(Loop.create)
    .forever(getAction) // <--- the step is only calculated once during compilation

  var getAction: ChainBuilder = {
    var c = r.nextDouble() * 100

    def getChance(percent: Double): Double = {
      c = c - percent
      c
    }

    if (getChance(27.7) < 0) { Log.putEvents }
    else if (getChance(18.3) < 0) { Log.putBinary }
    else if (getChance(17.2) < 0) { Loop.list }
    else if (getChance(14.7) < 0) { Key.listIncomingRequests }
    else { Account.get }
  }


Reply all
Reply to author
Forward
0 new messages