How to Test a gRPC Service in CI
grpcurl calls gRPC methods from the shell and ghz drives a load smoke, both over server reflection.
Use grpcurl to invoke a method and assert on the JSON reply, then optionally run ghz for a small load smoke against the same service.
Steps
- Enable server reflection or mount the
.protofiles. - Call a method with
grpcurl -dand assert on the reply. - Run
ghzfor a short load smoke and check the error rate.
Workflow
.github/workflows/ci.yml
jobs:
grpc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
./server &
npx wait-on tcp:50051
- run: |
grpcurl -plaintext -d '{"id":"1"}' \
localhost:50051 users.UserService/GetUser | jq -e '.name'
- run: |
ghz --insecure --proto users.proto \
--call users.UserService/GetUser \
-d '{"id":"1"}' -n 200 -c 10 localhost:50051Gotchas
- Use
-plaintextonly against a local test server, never against a TLS production endpoint. - Wait on
tcp:50051because gRPC has no HTTP health path to poll by default.
Related guides
How to Start the API and Wait for It Before Testing in CIStart your API in the background and block until it is ready with wait-on before API tests run in GitHub Acti…
How to Run an API Load Smoke With k6 in CIRun a short k6 load smoke against an API in GitHub Actions, setting a p95 latency and error-rate threshold so…
How to Write Rate-Limit-Aware API Tests in CIKeep API tests from tripping rate limits in GitHub Actions by honoring Retry-After, backing off on 429s, and…