Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gatling switch protocols during scenario

Tags:

gatling

I'm trying to create a Gatling scenario which requires switching the protocol to a different host during the test. The user journey is

https://example.com/page1
https://example.com/page2
https://accounts.example.com/signin
https://example.com/page3

so as part of a single scenario, I need to ether switch the protocol defined in the scenario set up, or switch the baseUrl defined on the protocol but I can't figure out how to do that.

A basic scenario might look like

package protocolexample

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class Example extends Simulation {
  val exampleHttp = http.baseURL("https://example.com/")
  val exampleAccountsHttp = http.baseURL("https://accounts.example.com/")

  val scn = scenario("Signin")
    .exec(
      http("Page 1").get("/page1")
    )
    .exec(
      http("Page 2").get("/page2")
    )
    .exec(
      // This needs to be done against accounts.example.com
      http("Signin").get("/signin")
    )
    .exec(
      // Back to example.com
      http("Page 3").get("/page3")
    )

  setUp(
    scn.inject(
      atOnceUsers(3)
    ).protocols(exampleHttp)
  )
}

I just need to figure out how to ether switch the host or protocol for the 3rd step. I know I can create multiple scenarios but this needs to be a single user flow across multiple hosts.

I've tried directly using the other protocol

exec(
  // This needs to be done against accounts.example.com
  exampleAccountsHttp("Signin").get("/signin")
)

which results in

protocolexample/example.scala:19: type mismatch;
 found   : String("Signin")
 required: io.gatling.core.session.Session
       exampleAccountsHttp("Signin").get("/signin")

and also changing the base URL on the request

exec(
  // This needs to be done against accounts.example.com
  http("Signin").baseUrl("https://accounts.example.com/").get("/signin")
)

which results in

protocolexample/example.scala:19: value baseUrl is not a member of io.gatling.http.request.builder.Http
like image 875
Smudge Avatar asked Apr 04 '16 12:04

Smudge


People also ask

How do you run scenarios sequentially in Gatling?

Save this answer. Show activity on this post. As of Gatling 3.3, there's no real way to run scenarios sequentially. The only solution is to start the other scenarios after some delay, see nothingFor.

What is session in Gatling?

Technically speaking, the session is the state of a virtual user. It is basically, a map with key strings. As, MAP[string, anystr] . Entries in a map are called Session attributes.

What is Gatling simulation?

Gatling is a load testing tool that comes with excellent support of the HTTP protocol – which makes it a really good choice for load testing any HTTP server. This quick guide will show you how to setup a simple scenario for load testing an HTTP server.


1 Answers

You can use an absolute URI (inclusive protocol) as a parameter for Http.get, Http.post and so on.

class Example extends Simulation {
  val exampleHttp = http.baseURL("https://example.com/")
  val scn = scenario("Signin")
    .exec(http("Page 1").get("/page1"))
    .exec(http("Page 2").get("/page2"))
    .exec(http("Signin").get("https://accounts.example.com/signin"))
    .exec(http("Page 3").get("/page3"))
  setUp(scn.inject(atOnceUsers(3))
    .protocols(exampleHttp))
}

see: https://gatling.io/docs/current/cheat-sheet/#http-protocol-urls-baseUrl

baseURL: Sets the base URL of all relative URLs of the scenario on which the configuration is applied.

like image 120
Meiko Rachimow Avatar answered Oct 02 '22 04:10

Meiko Rachimow