Assertion on the HTTP status code

Hello to all!

I have the following use case:

  • I want to run a simulation (or maybe a set of simulations in the future) and assert if the simulation ran “successful” or not
  • I define “Successful” as = no request got an HTTP Status Code 400 returned
  • If there is a single HTTP Status code 400, the simulation should fail (e.g. maven should provide a “Build failure” or a exit code 1)

Maybe the use case seems awkward, but my plan is to publish a successful run further to my colleagues. If the simulation has an error (aka a 400 error was returned), it should not be published any further.

On the assertion page here, I found, that there could be assertions, but those target “only” on the times/percentiles.

Do you know a solution for this?

Best regards!

On the assertion page here, I found, that there could be assertions, but those target “only” on the times/percentiles.

No they don’t.

global().failedRequests().count().is(0)

Your 400 responses will trigger failures as explained here.

1 Like

I have created example for Your Case:
Case0019WhenStatusCode400ThenFailSimulation

I forgot exclude it so my build is failed on GitHub :rofl:

2 Likes

Hello!

Thank you very much @slandelle and @GeMi for your help and your support!

Your solution counts HTTP 5xx errors as “failed requests” too. But I do not want to consider those requests-responses, because those errors are not caused by my Gatling simulation but by the BE or infrastructure. So my intention is, if my simulation does not produce any 4xx errors, I continue with further steps.

Hmmm :thinking: … yesterday I found this solution in powershell though:

$lastrun=Get-Content ./target/gatling/lastRun.txt
$nomatches=(Get-Content ./target/gatling/$lastrun/simulation.log | Select-String -Pattern 'found 4\d{2}').Matches.Length
if ($nomatches -gt 0) { 
  exit 1
}

So, if a 4xx error is logged in the last ‘simulatioin.log’ file, I exit the pipeline respectively the GitHub Action. Feels hacky, but it works quite well so far.

I’ll let you know if I can come up with a better solution. But for now, I leave everything like it is.

Thanks guys for your help … and also for this great community here!
Kind regards!

If you look in @GeMi code, you’ll see that only 400 will fail the request thank to .check(status().not(400)).

Does that help you?

Cheers!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.