2

I have following scenario

  .tryMax(10) {
    pause(200 millis)
    exec(
      http("monitor status")
        .get("/${orderId}")
        .headers(sentHeaders)
        .check(status is 200)
        .check(jsonPath("$.status").is("SUCCESSFUL"))
    )
  }
  // next request

I expect this to call my endpoint up to 10 times until the condition status=SUCCESSFUL is met. It does this correctly and only executes the next request after the condition is met. However, the test result still reports it as a failure.

---- Errors --------------------------------------------------------------------
> jsonPath($.status).find.is(SUCCESSFUL), but actu    992 (100.0%)
ally found ACCEPTED

Why is it reporting the request inside the tryMax as an error?

isADon
  • 3,433
  • 11
  • 35
  • 49

1 Answers1

1

That's the expected behavior for tryMax.

Use an asLongAs loop and a non failing check where you would save the extracted value to be used for the loop condition.

Stéphane LANDELLE
  • 6,076
  • 2
  • 10
  • 12
  • I agree with @isADon, I would only expect this as a failure if NO retry ever succeeds. I also tried the suggested `asLongAs` same result - all worked fine in the end - but the report tells me I have 5 errors. – pme Jul 30 '21 at 11:55
  • @pme Why you have errors when using asLongAs WITH a non failing check? Make sure to use a loop condition based on a failing check, eg `optional` condition. – Stéphane LANDELLE Jul 30 '21 at 12:54
  • ok that worked - thanks - my check really failed. But what if you do not have an optional condition and you need a `tryMax` (my example is a 404 until it is created). In this case I have failures even so this is expected (as the question suggests) – pme Aug 02 '21 at 06:09
  • Use `tryMax` for unexpected failures, eg getting 500 on login because system starts failing under load. In you case, you could use a `doWhile` loop and a `status.in(200, 404)` check. – Stéphane LANDELLE Aug 02 '21 at 08:29
  • Thanks now I get it - there is a default check for status that is overwritten if any status.* check is added. – pme Aug 02 '21 at 12:01
  • 1
    Indeed, see https://gatling.io/docs/gatling/reference/current/http/check/#http-status – Stéphane LANDELLE Aug 02 '21 at 12:52