Options for failing a test from setup

Looking at running pings for our servers in setup and if not 200, then end the test. I was looking a checks and thresholds but not sure how to proceed. This is a workflow test and is pretty long so would not want to run in our pipeline if the servers are not available. Any helpful hints or pointers to some feature I may have missed will be greatly appreciated. BTW newby on K6.
Thanks!

I am not sure I completely understand your use case, but you can probably have a constant-arrival-rate scenario that regularly (e.g. once every second) checks your criteria. And then either call test.abort() in the k6/execution module to stop the test when it fails, or use a custom metric (e.g. Counter) and a threshold on it with abortOnFail: true.

I was wondering if the threshold would work in the setup method? I was going down that path but unsure. I just want to have a pass/fail check in setup, if pass then continue, if fail abort test. Thanks Ned!

Ah, sorry, I missed that you want to do this check in the setup() function :man_facepalming: In there, it’s even easier! test.abort() will still work, but also any exception thrown in setup() will also abort the test :slight_smile:

1 Like