4
votes

I try to make an injection with a variety of "breaks" and "atOnceUsers". I didn't found a nice solution on the documentation for that.

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)
}
1

1 Answers

2
votes

I think you've discovered a missing feature in Gatling! I'm going to develop this a bit more and submit a pull request to the Gatling team to (hopefully) get it into the project, but in the meantime, you can get the functionality you desire by providing your own custom InjectionStep implementation - just paste this at the top of your Simulation file:

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 tried to do with atOnceUsers, but the key difference is the counting is within the chain method, which will get the incrementing behaviour you wanted because chain will be called each time Gatling decides it's time to send some requests.

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

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