Skip to content

Commit b8d1c76

Browse files
authored
stress: make the client log the total number of calls made (#6762)
1 parent a5a7ef2 commit b8d1c76

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

stress/client/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"strconv"
2929
"strings"
3030
"sync"
31+
"sync/atomic"
3132
"time"
3233

3334
"google.golang.org/grpc"
@@ -55,7 +56,8 @@ var (
5556
tlsServerName = flag.String("server_host_override", "foo.test.google.fr", "The server name use to verify the hostname returned by TLS handshake if it is not empty. Otherwise, --server_host is used.")
5657
caFile = flag.String("ca_file", "", "The file containing the CA root cert file")
5758

58-
logger = grpclog.Component("stress")
59+
totalNumCalls int64
60+
logger = grpclog.Component("stress")
5961
)
6062

6163
// testCaseWithWeight contains the test case type and its weight.
@@ -206,7 +208,6 @@ func startServer(server *server, port int) {
206208
s := grpc.NewServer()
207209
metricspb.RegisterMetricsServiceServer(s, server)
208210
s.Serve(lis)
209-
210211
}
211212

212213
// performRPCs uses weightedRandomTestSelector to select test case and runs the tests.
@@ -241,6 +242,7 @@ func performRPCs(gauge *gauge, conn *grpc.ClientConn, selector *weightedRandomTe
241242
interop.DoCustomMetadata(client, grpc.WaitForReady(true))
242243
}
243244
numCalls++
245+
defer func() { atomic.AddInt64(&totalNumCalls, numCalls) }()
244246
gauge.set(int64(float64(numCalls) / time.Since(startTime).Seconds()))
245247

246248
select {
@@ -335,6 +337,6 @@ func main() {
335337
close(stop)
336338
}
337339
wg.Wait()
340+
logger.Infof("Total calls made: %v", totalNumCalls)
338341
logger.Infof(" ===== ALL DONE ===== ")
339-
340342
}

0 commit comments

Comments
 (0)