How to create threshold based on another metric

I’m building a test to confirm that each HTTP API call generates a WebSocket message, and would like to set up a threshold that the number of WebSocket messages received is the same as the number of HTTP API calls I’ve made.

Example:

const expectedMessages = new Counter('ws_messages_expected');
const receivedMessages = new Counter('ws_messages_received');

export const options = {
    thresholds: {
        'ws_messages_received': ['count==ws_messages_expected.count']
    }
}

Is this possible in k6? If so how? If not, are there other ways to accomplish this?

Hi @shawmanz32na !

Welcome to the community forums! :wave:

As far as I know, we can’t directly compare the metrics in the thresholds.

I believe what’s possible is to compare the number of the WS & HTTP calls by iteration (you need to introduce a few local variables) and either check this directly or create a new metric that could be used with the threshold (let’s say some failures are possible).

Let me know if that answers,
Cheers!