RampUp variable with Gatling

I am trying to do injection with various "breaks" and "atOnceUsers". I have not found a suitable solution for the documentation.

My approach was to create a function called "getNextNumber ()" with a local counter to increase the number of "atOnceUsers", but the function was only called once at the beginning.

Any ideas?

My code:

class TestCombinationGetFiles extends Simulation {
    var counter: Int =1 

    def getNextNumber():Int = {
      counter+= 1
      return counter
    }     

  val Get20Files = scenario("get20Files")
   .feed(UuidFeeder.feeder)
   .exec(WebAuth.AuthenticateUser)
   .pause(30)
   .exec(WebCloudContent.GoToTestFolder20)

 val Get10Files = scenario("get10Files").feed(UuidFeeder.feeder)
  .exec(WebAuth.AuthenticateUser)
  .pause(15)
  .exec(WebCloudContent.GoToTestFolder10)

 val loadFolder20TestRamp =            
  scenario("loadFolder20TestRamp").exec(WebAuthSwisscom.AuthenticateUser,             
   WebCloudContentSwisscom.GoToTestFolder20)    

 setUp(Get20Files.inject(
    splitUsers(36) into( 
        atOnceUsers(getNextNumber())) 
        separatedBy(30 seconds)) 

        /* messy Code with correct functionality
        atOnceUsers(1),
        nothingFor(30 seconds),
        atOnceUsers(2),
        nothingFor(30 seconds),
        atOnceUsers(3),
        nothingFor(30 seconds),
        atOnceUsers(4),
        nothingFor(30 seconds),
        atOnceUsers(5),
        nothingFor(30 seconds),
        atOnceUsers(6),
        nothingFor(30 seconds),
        atOnceUsers(7),
        nothingFor(30 seconds),
        atOnceUsers(8),
        nothingFor(30 seconds))
        */
    ,
    Get10Files.inject(
        splitUsers(16) into( 
           atOnceUsers(1)) 
           separatedBy(15 seconds)) 
   ).protocols(WebSetUp.httpProtocol)
}

      

+3


source to share


1 answer


I think you've found the missing feature in Gatling! I'm going to develop this a little more and send a pull request to the Gatling team to (hopefully) get it in the project, but in the meantime you can get the functionality you want by providing your own implementation InjectionStep

- just paste this at the top of your file Simulation

:

import io.gatling.core.controller.inject._
import scala.concurrent.duration._

case class AtOnceIncrementalInjection(users: Int) extends InjectionStep {
  require(users > 0, "The number of users must be a strictly positive value")
  var count = users

  override def chain(chained: Iterator[FiniteDuration]): Iterator[FiniteDuration] = {
    val currentUsers = count
    count += 1
    Iterator.continually(0 milliseconds).take(currentUsers) ++ chained 
  }
}

def atOnceIncrementalUsers(initialUsers:Int) = AtOnceIncrementalInjection(initialUsers)

      

This is basically what you were trying to do with atOnceUsers

, but the key difference is the counting inside the method chain

, which will get the desired step-by-step behavior, since it chain

will be called every time Gatling decides it's time to send some requests.



Now you can just use the helper function the same way you used atOnceUsers

:

splitUsers(36) into( 
    atOnceIncrementalUsers(1)) 
    separatedBy(30 seconds)) 

      

+1


source







All Articles