This document introduces how to orchestrate a gRPC protocol request.
Basic Usage
By using the APIs provided by the pts/grpc module, you can create a gRPC client and send gRPC requests. Protocol File Upload
Upload your defined .proto file by choosing PTS > Test Scenarios > Create Scenario > File Management > Protocol File.
Script Writing
Create a gRPC client, and then use the following methods provided by the client to write your logic:
load
: Loads and parses the .proto file you uploaded.
connect
: Establishes a connection with the gRPC server.
invoke
: Initiates an RPC call and obtains the response.
close
: Closes a connection.
Examples of the .proto file and scenario script are as follows:
syntax = "proto3";
package addsvc;
service Add {
rpc Sum (SumRequest) returns (SumReply) {}
}
message SumRequest {
int64 a = 1;
int64 b = 2;
}
message SumReply {
int64 v = 1;
string err = 2;
}
Scenario script:
import grpc from 'pts/grpc';
const client = new grpc.Client();
client.load([], 'addsvc.proto');
export default () => {
client.connect('grpcb.in:9000', { insecure: true });
const rsp = client.invoke('addsvc.Add/Sum', {
a: 1,
b: 2,
});
console.log(rsp.data.v);
client.close();
};
File Dependency
In the performance testing scenario, you can upload the following types of files to provide status data during the execution of the performance testing task:
Parameter file: It dynamically provides test data in CSV format. That is, when the scenario is executed by each concurrent user (VU), each line of data will be obtained from the parameter file as the test data values for reference by variables in the script. For specific usage, see Using Parameter Files. Request file: It is required for constructing your request, for example, the file that needs to be uploaded. For specific usage, see Using Request Files. Protocol file: It is required for request serialization. For specific usage, see Using Protocol Files.