Skip to content

Instantly share code, notes, and snippets.

@flynnbops
Created August 23, 2021 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flynnbops/17fd64a78d49bade5f3f0b0a378a32cb to your computer and use it in GitHub Desktop.
Save flynnbops/17fd64a78d49bade5f3f0b0a378a32cb to your computer and use it in GitHub Desktop.
Gatling basic simualtion
// Simulation I've ended up with at the end of the Gatling academy introduction course
//https://academy.gatling.io/courses/take/Run-your-first-tests-with-Gatling/lessons/16252154-gatling-introduction-course-overview
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class computerDatabaseSimulation extends Simulation {
// Defines the baseURL of the SUT
val httpProtocol = http
.baseUrl("https://computer-database.gatling.io")
// Actions to perform a search
object Search{
val searchFeeder = csv("../resources/search.csv").random
val search = exec(http("Load_Homepage")
.get("/computers"))
.pause(2)
.feed(searchFeeder)
.exec(http("Search_${searchCriterion}")
.get("/computers?f=${searchCriterion}")
.check(css("a:contains('${searchComputerName}')", "href").saveAs("computerURL")))
.pause(1)
.exec(http("View_Details_${searchComputerName}") // Get a computers details
.get("${computerURL}"))
.pause(1)
}
// Actions to create a computer
object Create{
val computerFeeder = csv("../resources/computers.csv").circular
val create = exec(http("Load_Create_Computers_Page")
.get("/computers/new"))
.pause(2)
.feed(computerFeeder)
.exec(http("Create_Computer_${computerName}") // Create a computer
.post("/computers")
.formParam("name", "${computerName}")
.formParam("introduced", "${introduced}")
.formParam("discontinued", "${discontinued}")
.formParam("company", "${companyID}")
.check(status.is(200)))
}
// Actions to delete a computer
object Delete{
val delete = exec(http("Delete_Computer") // Delete a computer
.post("/computers/381/delete"))
}
// User profiles
val admins = scenario("Admins")
.exec(Search.search, Create.create, Delete.delete)
val guests = scenario("Guests")
.exec(Search.search)
// Basic simulations
// setUp(admins.inject(atOnceUsers(1))).protocols(httpProtocol)
// setUp(guests.inject(atOnceUsers(4))).protocols(httpProtocol)
// More interesting simulation with 2 user profiles
setUp(admins.inject(atOnceUsers(5)),
guests.inject(
nothingFor(5),
atOnceUsers(1),
rampUsers(5) during(10),
constantUsersPerSec(20) during(20)
))
.protocols(httpProtocol)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment