Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: custom metrics and assertions #4196

Open
domi-nika60 opened this issue Jan 24, 2022 · 4 comments
Open

Core: custom metrics and assertions #4196

domi-nika60 opened this issue Jan 24, 2022 · 4 comments

Comments

@domi-nika60
Copy link

domi-nika60 commented Jan 24, 2022

Hi,

I'm unable to make assertion in exec block of code (Scala test) that fails the test if it's not passed.
My Gatling version I'm using is '3.7.3'

I'm doing request to http separately like:

 val request = exec {
    http("GET SOMETHING")
      .get(<some endpoint>)
      .header(<some header>)
      .check(status.exists, status.saveAs("get.statusCode"))
}

And then I'm using it in definition of function like:

def someFunction = {
     exec(
        request.during(<some time>) {
           exec(
             session => {
              allRequests += 1
              if (session("get.statusCode").as[Int] == 200) {
                successes += 1
              }
              session
            }
          )
})

I'd like to add some assertion in this someFunction to check, if percentage of successful requests (statusCode == 200) is not less than 10.

I've tried adding something like:

        assert((successes*100)/allRequests >= 10))

But it does not fail the test scenario, when it's below that 10%.
I've tried using exitHereIfFailed or any of those types from Gatling documentation (but with no luck).

Moreover, I also added .assertions(forAll.failedRequests.count.is(0)) in setUp section. This also did not work (test is still ending with Build Successful).

I'm aware, there is also possibility to use an assertion for global requests (assertions(global.successfulRequests.percent.gt(10))), but I need my custom one.

Also I do not want to use any check, because counters (allRequests and successes) must be in request.during(<some time>) block.

Is there any option to use my custom counters and check percentage of successful request as in my example?

@domi-nika60 domi-nika60 changed the title HTTP - unable to create assertion in session exec (Question / FeatureRequest) HTTP - unable to create assertion in session exec Jan 24, 2022
@slandelle
Copy link
Member

We want assertions to be:

  • serializable over the wire (hence use an AST, not arbitrary functions)
  • computed against Gatling metrics (not arbitrary ones you would compute manually)

In short, you would like Gatling to have custom metrics (counters, but others might want durations, often called timers) and that they support assertions.

That's something we're considering, but it will probably only make its way in Gatling Enterprise.

@domi-nika60
Copy link
Author

Okey, I see. Thanks for so fast response.
In this situation, is there any other way to check if e.g. at least 10% requests return proper value?

@slandelle
Copy link
Member

Can't you explicitly check for status 200, instead of using the default one?

@slandelle slandelle changed the title (Question / FeatureRequest) HTTP - unable to create assertion in session exec Core: custom metrics and assertions Jan 24, 2022
@domi-nika60
Copy link
Author

I was thinking about it. But the counters are not working properly in this http request exec. So that, I assumed that I need to use them in request.during(<some time>) block. Am I doing sth wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants