how may I assert a value is less than a threshold?

Hi,

I’ve been using gatling on and off for a year now. I really like it. I’m load testing a REST service and we recently found a thread leak. So the developers wrote a ‘canary page’ that just returns the number of threads used by the JVM. I’d like to assert that the thread count doesn’t go above 200. Is there a way to do that?

Here’s my HTTP traffic
`

GET /op/canary
body: {
“name”: “JVM:Info”,
“information”: {
“Used Heap”: “163.9 MB”,
“Thread Count”: “41”
}

`

I can use this jsonPath to find the value but I don’t how to check that it is less than 200…

`

check(
status.is(200),
jsonPath("$…[?(@.name=‘JVM:Info’)].information.‘Thread Count’"))
)

`

Now what? How do I check for less than 200?

Thanks,
Shayne

I’m using Gatling 2.2.2

Hi,

You could try a combination of ofType[Int] and lessThan(), but there are some caveats:

  • ofType[Int] needs the original value to be typed int, here “41” is a string, so it won’t work
  • Your jsonPath doesn’t look valid, the first comparison needs a double equal sign, such as @.name == ‘JVM:Info’, and the .‘Thread Count’ notation isn’t the right way to do it either, take a look at the spec here: https://github.com/gatling/jsonpath/blob/master/README.md
    Cheers,

Guillaume.

The name of the json field is ‘Thread Count’ so how does scala’s JsonPath want me to reference that field? What would a correct jsonpath look like?
FWIW, I wrote that jsonpath with the help of https://jsonpath.curiousconcept.com/
Is there a better jsonpath checker for gatlings implementation?

The original question is this, "How can I assert/check that some value in a response body is lessThan or greaterThan some known value or a variable.
Here’s what I came up with. It seems clunky so I’m hoping someone can improve it! I hope there is someway to do a check on a session variable, but I couldn’t figure it out so I hacked around it with a checkIf(), then a bogus call to substring(), which just helps me to know what I was really trying to test. Please, I’d really like a cleaner solution to the problem.

`
val getCanaryPage =
during(TestEnvironment.duration) {
exec(http(“getCanaryPage”)
.get(TestEnvironment.pathAccService+“op/canary”)
.basicAuth(“username”, pwd)
.check(jsonPath("$…[?(@.name==‘JVM:Info’)].information.ThreadCount").saveAs(“threads”))
.check(checkIf((response: Response, session: Session) => session(“threads”).as[String].toInt > 100)(substring(“threads exceeded 100”)))
) //exec
.pause(10)
} //during

`

Objectively, as this API is yours, you really should improve its design:

  • Thread Count is a number, so your API shouldn’t expose it as a String, ie don’t wrap it with double quotes

  • Don’t use a white space is a field name, you’re just making things a harder for you
    Then:

  • check out the check API documentation to figure out how to explicitly set the captured value type

  • check the JsonPath spec for another notation, different from the dot one, so you can pass a name with a white space