Skip to content

Commit

Permalink
stress: make the client log the total number of calls made (#6762)
Browse files Browse the repository at this point in the history
  • Loading branch information
temawi authored Nov 6, 2023
1 parent a5a7ef2 commit b8d1c76
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions stress/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"time"

"google.golang.org/grpc"
Expand Down Expand Up @@ -55,7 +56,8 @@ var (
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.")
caFile = flag.String("ca_file", "", "The file containing the CA root cert file")

logger = grpclog.Component("stress")
totalNumCalls int64
logger = grpclog.Component("stress")
)

// testCaseWithWeight contains the test case type and its weight.
Expand Down Expand Up @@ -206,7 +208,6 @@ func startServer(server *server, port int) {
s := grpc.NewServer()
metricspb.RegisterMetricsServiceServer(s, server)
s.Serve(lis)

}

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

select {
Expand Down Expand Up @@ -335,6 +337,6 @@ func main() {
close(stop)
}
wg.Wait()
logger.Infof("Total calls made: %v", totalNumCalls)
logger.Infof(" ===== ALL DONE ===== ")

}

0 comments on commit b8d1c76

Please sign in to comment.