Doesn't k6/experimental/grpc support the check method for server streaming yet?

Doesn’t k6/experimental/grpc support the check method for server streaming yet?

Hi @kworkbee

Welcome to the community forums :wave:

Could you please elaborate? What do you mean by check’s support for server streaming?

Thanks!

Hi @olegbespalov ! I mean checks.
I sent a request for each group of http and grpc (server streaming), and I asked because I thought I couldn’t use checks at the same time as using Stream API.

The check is just a function that validates some conditions.

It can be used even for the Streaming API, but the critical part is remembering that the Streaming API is asynchronous, meaning that the check should be located in the right place.

For example, let’s say you expect that 100 messages should come from the stream.

Then the code could looks like:

export default () => {
  client.connect(GRPC_ADDR, { plaintext: true });

  const stream = new Stream(client, 'main.FeatureExplorer/ListFeatures', null);

  // our main counter for the check
  let counter = 0;

  stream.on('data', function (feature) {
    counter++;
    // any other logic
  });

  
 stream.on('end', function () {
    // The server has finished sending
    client.close();
    console.log('All done ' + counter + ' features received.');

    //At that point, we know that we could check
    check(counter, { 'received 100 features': (c) => c === 100 });
  });
};

Hope that answers!
Cheers