Is this KO expected behavior when 401 is returned even with check status?

I have the following piece of code

def create(payload: String):
ChainBuilder = exec(http(“Create”)
.post(EndPoint + “?_action=create”)
.headers(getAuthHeaders("${%s}".format(token)))
.body(StringBody(payload)).asJson
.check(jsonPath("$._id").find.saveAs(var))
.check(status.in(201, 403, 401).saveAs(“savedStatus”)))

Subsiquently in a feedeer i call the above as follows

.exec(create())

.doIfEquals("${savedStatus}", 401) {

exec(gettoken())
.exec(create())
}

This however is resulting in an undesired KO when a 401 is returned from the server. I thoguht that the “.check(status.in(…,401)” will inhibit the KO? Is my understanding incorrect. If it is then is there a way to avoid registering a KO?

Thanks

If you set an explicit check that allows 401 status, request won’t be KO on 401.
Make sure:
• you’re using the latest version: 3.6.1
• you’ve set your check on the correct request

Note: your code sample has create() while your create method takes a String body parameter. It’s impossible to properly help you unless you provide code that compiles properly.

So i did upgrade from 3.3.1 to 3.6.1 but still run into the same issue. Here is the http POST when create() is called.

HTTP request:
POST https://login.example.com/app/user/?_action=create
headers:
user-agent: Robot/Gatling
Authorization: Bearer abcdefgh
accept: application/json
host: login.example.com
content-type: application/json
content-length: 311
body:StringChunksRequestBody{contentType=‘application/json’, charset=UTF-8, content={
“userName” : “James”,
“givenName” : “Bond”,
“sn” : “Bond”,
“mail” : “bond@gmail.com”,
“telephoneNumber” : “444-444-4444”,
“password” : “xasdfasdfsdfsafdsf”
}}

And sorry i missed the response which is 401 and as you can see is being checked as follows, yet i am still getting a KO which is equal to the number of concurrency.

.check(status.in(201, 403, 401).saveAs(“savedStatus”)))

So will this considered a bug or am i still doing something wrong. To summarize the response HTTP code is “401” and i have “check(status.in(201,401,403)” and yet a KO is counted towards the 401.

I’ve tried to reproduce, but to no avail. You can try the following and check for yourself:

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class StatusCheckWorkload extends Simulation {

  val httpProtocol = http
    .baseUrl("[https://gatling.io](https://gatling.io)")
    .acceptEncodingHeader("gzip, deflate")
    .disableWarmUp

  val scn = scenario("scenario")
    .exec(http("404").get("/undefined")
    .check(status.in(200, 404)))

  setUp(
    scn.inject(atOnceUsers(1))
  ).protocols(httpProtocol)
}

It’s very likely that the error is on your side.

Please comply to this group’s terms:

  • Provide a Short, Self Contained, Correct (Compilable), Example (see http://sscce.org/)

Yes indeed it was my own doing. I was just looking at the KO without paying attention to the actual reason which is another “check” in my sequence of steps which was failing and hence contributing to the KO. Sorry for the false alarm.