Load Testing · Middle · Question 17 of 76
A login endpoint should return 401 for wrong passwords in your test. How do you keep it out of http_req_failed?
- 1Mark 401 as expected:
http.setResponseCallback(http.expectedStatuses(200, 401)) - 2Wrap the request in try/catch, so k6 won't count the 401 response as a failure
- 3Add
sleep()right after the request, so k6 ignores the failure in the metric
Show the answer
Correct answer: Mark 401 as expected: http.setResponseCallback(http.expectedStatuses(200, 401))
Explanation
The response callback decides which statuses count as success for http_req_failed and the expected_response tag.