xk6-grpc-web is a k6 extension that supports gRPC-Web protocol.
This extension is built using xk6, a tool for building custom k6 binary.
xk6 build --with github.com/shota3506/xk6-grpc-web
import grpcweb from "k6/x/grpc-web";
import { check } from "k6";
const GRPC_WEB_ADDR = __ENV.GRPC_WEB_ADDR;
let client = new grpcweb.Client();
client.load([], "PATH_TO_PROTO_FILE");
export default () => {
client.connect(GRPC_WEB_ADDR);
data = {};
const response = client.invoke("/helloworld.Greeter/SayHello", data);
check(response, {
"status is OK": (r) => r && r.status === grpcweb.StatusOK,
});
console.log(JSON.stringify(response));
client.close();
};
import grpcweb from "k6/x/grpc-web";
import { sleep } from "k6";
const GRPC_WEB_ADDR = __ENV.GRPC_WEB_ADDR;
let client = new grpcweb.Client();
client.load([], "PATH_TO_PROTO_FILE");
export default () => {
client.connect(GRPC_WEB_ADDR);
data = {};
const stream = client.stream("/helloworld.Greeter/SayRepeatHello", data);
stream.on("data", (data) => {
console.log("Data: " + JSON.stringify(data));
});
stream.on("error", (e) => {
console.log("Error: " + JSON.stringify(e));
});
stream.on("end", () => {
console.log("Done");
client.close();
});
sleep(0.1);
};
See examples for runnable examples.