Catch Signals in k6

I’d like to be able to handle a CONTROL-C (SIGINT) in Windows or Mac. For node one could use the death module or process.on. Any suggestions how to do this in k6?

Hi @hptabster,
what is your intent in handling a CTRL-c command? Do you want to execute some code before the process stops?

Did you already check the teardown stage? It allows you to execute some code at the end of the test life cycle.

Let me know if it helps.

Sometimes the interrupts do not provide end of session metrics or other teardown operations (like a websocket message before closing the socket). Is there any reason why k6 cannot handle signals?

Hi @hptabster,

Is there any reason why k6 cannot handle signals?

We may have some features in the future for better handling interrupts, for example, you can check Improve handling of extension shutdown · Issue #2432 · grafana/k6 · GitHub. In any case, they are long-term plans because they are not yet defined and they impact the test life-cycle where we have to pay high attention when we add a new API.

do not provide end of session metrics

In this specific case, it could require hitting CTRL-c twice in the case that k6 is blocked by the connection taking longer to read/write.

like a websocket message before closing the socket

If the attempt here is to close the connection then this is not required because it’s already covered by the WebSocket module as you can read from these lines of the k6’s code.

The action on on CTRL-C (SIGINT) could be to send some messages on the socket BEFORE closing it.