As topic say. I couldn’t find any other documentation to answer this question, so I was wondering where I could find an official website or community member to answer it?
When a request fails or when an Exception is thrown.
hi slandelle,thanks for your reply.
but I am requesting a non-existent path, but return true.
Is that normal?
Maybe my code is wrong. Can you point it out for me?
Here’s an example
HttpProtocolBuilder httpProtocol =
http.baseUrl("https://computer-database.gatling.io")
.acceptHeader("application/json")
.contentTypeHeader("application/json");
ScenarioBuilder myFirstScenario = scenario("My First Scenario")
.exec(session -> {
System.out.println("before request session state: " + session.isFailed());
return session;
})
.exec(http("Request 1")
.get("/non-existent")
.check(status().is(200))
)
.exec(session -> {
System.out.println("after request session state: " + session.isFailed());
return session;
});
Nothing mysterious here.
The response to this request has a 404 status, so the status().is(200)
check fails and marks the session as failed.
I’m understanding your code:
HttpProtocolBuilder httpProtocol =
http.baseUrl("https://computer-database.gatling.io")
.acceptHeader("application/json")
.contentTypeHeader("application/json");
This is just for set up, no request has been made yet. Then you make the call with this workflow
ScenarioBuilder myFirstScenario = scenario("My First Scenario")
.exec(session -> {
System.out.println("before request session state: " + session.isFailed());
return session;
}) //this exec block will return true, because no API request has been made, so no fail condition fail found yet.
//at this exec block, a request has been made
.exec(http("Request 1")
.get("/non-existent")
.check(status().is(200)) //right here, the condition failed, thus set the session to fail
)
Session is then updated, from false to true due to status check condition failed, the result is returned from the last block.
.exec(session -> {
System.out.println("after request session state: " + session.isFailed());
return session;
});
So as Slandelle said, no mysteries.
@slandelle @trinp
thanks for you’re reply.
you’re right.I made a rookie mistake.
like slandelle say:
When a request fails or when an Exception is thrown.
it will auto change session state.
on my example 404 in session.isFailed() it has to be true.
because session.isFailed()
–true = yes. you got a bad request.
–false = no. you request so far so good.
I got the literal meaning wrong.
I would like to thank you again for your kind reply.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.