Hi @HardBoiledEG
I tried a similar script (I just had to change the status code as 99999
is not accepted in HTTP1.1):
import http from 'k6/http';
import { check, fail } from 'k6';
export default function () {
const res = http.get('https://httpbin.test.k6.io/status/999');
//const res = http.get('https://k6.io/');
if (
!check(res, {
'status code MUST be 200': (r) => r.status === 999,
})
) {
fail('status code was *not* 999');
}
}
This works well for me.
I find it a bit confusing that the check name is 'status code MUST be 200'
, while you check for 99999
. However, as in my example, if the endpoint is returning a 999
(or 99999
for you), it should work. I would just change the check name to make the script clearer, 'status code MUST be 999'
:
import http from 'k6/http';
import { check, fail } from 'k6';
export default function () {
const res = http.get('https://httpbin.test.k6.io/status/999');
//const res = http.get('https://k6.io/');
if (
!check(res, {
'status code MUST be 999': (r) => r.status === 999,
})
) {
fail('status code was *not* 999');
}
}
That said, when you say this stopped working, did you check if anything change in your SUT (System Under Test)?
I would suspect it’s not returning the status code you are checking for (be it 99999
- your script - or 9999
as your screenshot shows). I would check this with a curl
command, similar to:
curl -X GET "https://httpbin.test.k6.io/status/999" -v
And make sure it’s returning the status code you are checking for in the test script. In my case it’s indeed HTTP/1.1 999 UNKNOWN
:
< HTTP/1.1 999 UNKNOWN
< Date: Fri, 10 Mar 2023 14:01:31 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 0
< Connection: keep-alive
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
Let me know if that helps.
Cheers!