Skip to content

The Gatling Wait Plugin simplifies waiting for specific events in your testing scenarios by allowing customizable conditions, attempt management, and error handling.

License

Notifications You must be signed in to change notification settings

Amerousful/gatling-wait

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gatling Wait Maven Central

A solution built around Gatling DSL for a convenient way to wait for an event. Three key ingredients:

  1. A condition to wait for
  2. The number of attempts
  3. Pauses between attempts

Let's say you have an application with asynchronous logic, and you need to wait for a condition to be met. My real-life example involves creating a process with three statuses: processing, completed, and failed.

For instance, the endpoint to get the process status is https://application.com/status.

Here’s a request that polls and saves the status to the variable status:

 val getProcess = http("Get process")
    .get("/status")
    .check(
      jsonPath("$.status") saveAs "status"
    )

To wait:

import io.github.amerousful.wait._

val waitCompleted = Wait()
  .requestForPolling(getProcess)
  .waitUntil(condition("status")(_ == "completed"))
  .failOn(condition("status")(_ == "failed"))
  .terminalCheck(jsonPath("$.status") is "completed")
  .pauseDuration(1 second)
  .attempts(5)
  .init()

This waits for the status completed with 5 attempts and a 1 second pause between attempts. *Note that the pause duration consists of the pause plus the response time of a polling request, so the pause duration might fluctuate.

Additionally, it will fail if the status is failed, as there’s no need to wait for completed in that case.

Additional info:

condition("status")(_ == "completed")
              ↑             ↑ 
              |             | 
      variable name   condition to satisfy

OR

condition("status")(extracted => extracted == "completed")

You can also declare multiple conditions:

.waitUntil(
  condition("link")(_ != "empty"),
  condition("outdated")(_ == "false"),
)

.terminalCheck(
    jsonPath("$.link") is "empty",
    jsonPath("$.state.outdated") is "true",
  )

Make sure to add the same conditions in both the wait and the terminal check.

terminalCheck() - this check will execute when all attempts are reached, and its purpose is to fail the request if the conditions are not met.


This plugin records the number of attempts in the Session. The counter is stored as wait.attemptCounter -> {attemptNumber}.

Installation

Important: This plugin is compatible only with Gatling 3.9.5 and does not work with any versions above 3.9.5.

Maven:

Add to your pom.xml:

<dependency>
    <groupId>io.github.amerousful</groupId>
    <artifactId>gatling-wait</artifactId>
    <version>1.0</version>
</dependency>

SBT

Add to your build.sbt:

libraryDependencies += "io.github.amerousful" % "gatling-wait" % "1.0"

Import:

import io.github.amerousful.wait._

Logging

Add this to your logback.xml:

<logger name="io.github.amerousful.wait" level="ALL"/>

About

The Gatling Wait Plugin simplifies waiting for specific events in your testing scenarios by allowing customizable conditions, attempt management, and error handling.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages