I’m not sure exactly what I’m doing wrong here;
Snippet of code:
import { check, group, fail } from 'k6';
...
const res = http.post(url, payload, { headers });
const succeeded = res.json('succeeded') === true;
const message = res.json('message');
CounterErrors.add(!succeeded);
check(res, {
'response code was 200': (r) => r.status === 200,
'succeeded is true': (r) => succeeded,
}) || fail(`status was not 200 or it failed. Message: ${message}`);
duration.add(res.timings.duration, { my_tag: 'Duration' });
waiting.add(res.timings.waiting, { my_tag: 'Waiting' });
});
What I want it to do is:
- to check there is a 200 HTTP code and to check the JSON response for “succeeded: true”
- when one of those conditions fails, I want it to show an error message of “status was not 200 or it failed. Message:[then the actual error message]`”
Now it does both of those but I get a GoError mixed in for good luck:
ERRO[0002] GoError: status was not 200 or it failed. Message: An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy.
running at go.k6.io/k6/js/modules/k6.(*K6).Fail-fm (native)
default at file:///C:/Users/bob/desktop/test.js:55:16(86)
at go.k6.io/k6/js/modules/k6.(*K6).Group-fm (native)
at file:///C:/Users/bob/desktop/test.js:27:8(6) executor=shared-iterations scenario=default source=stacktrace
I’m guessing the GoError shouldn’t be there? Any idea what I’m doing wrong?
Edit: just to say, ignore the “An exception has been raised…” that is an error my side.
Thanks!!