Skip to content

Commit

Permalink
Slightly improve average calculation by using length of lats. Use eph…
Browse files Browse the repository at this point in the history
…emeral port for tests
  • Loading branch information
bojand committed Nov 15, 2018
1 parent f979538 commit f0acd05
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ type ResultDetail struct {
}

func newReporter(results chan *callResult, options *Options) *Reporter {

cap := min(options.N, maxResult)

return &Reporter{
options: options,
results: results,
Expand Down Expand Up @@ -123,7 +125,7 @@ func (r *Reporter) Run() {

// Finalize all the gathered data into a final report
func (r *Reporter) Finalize(total time.Duration) *Report {
average := r.avgTotal / float64(r.totalCount)
average := r.avgTotal / float64(len(r.lats))
avgDuration := time.Duration(average * float64(time.Second))
rps := float64(r.totalCount) / total.Seconds()

Expand Down
12 changes: 9 additions & 3 deletions requester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ghz

import (
"net"
"strconv"
"sync"
"testing"
"time"
Expand All @@ -15,11 +16,11 @@ import (
"google.golang.org/grpc/credentials"
)

const port = ":50051"
const localhost = "localhost:50051"
var port string
var localhost string

func startServer(secure bool) (*helloworld.Greeter, *grpc.Server, error) {
lis, err := net.Listen("tcp", port)
lis, err := net.Listen("tcp", ":0")
if err != nil {
return nil, nil, err
}
Expand All @@ -39,9 +40,14 @@ func startServer(secure bool) (*helloworld.Greeter, *grpc.Server, error) {
gs := helloworld.NewGreeter()
helloworld.RegisterGreeterServer(s, gs)
// reflection.Register(s)

port = strconv.Itoa(lis.Addr().(*net.TCPAddr).Port)
localhost = "localhost:" + port

go func() {
s.Serve(lis)
}()

return gs, s, err
}

Expand Down
4 changes: 1 addition & 3 deletions stats_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"google.golang.org/grpc"
)

const address = "localhost:50051"

func TestStatsHandler(t *testing.T) {
_, s, err := startServer(false)

Expand All @@ -32,7 +30,7 @@ func TestStatsHandler(t *testing.T) {
done <- true
}()

conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithStatsHandler(&statsHandler{rChan}))
conn, err := grpc.Dial(localhost, grpc.WithInsecure(), grpc.WithStatsHandler(&statsHandler{rChan}))

if err != nil {
assert.FailNow(t, err.Error())
Expand Down

0 comments on commit f0acd05

Please sign in to comment.