Skip to content

Commit

Permalink
Test which reproduce the problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ezsilmar committed Jul 4, 2019
1 parent 4c15615 commit b5753d6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion runner/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (r *Reporter) Run() {
r.lats = append(r.lats, res.duration.Seconds())
r.errors = append(r.errors, "")
r.statuses = append(r.statuses, res.status)
r.timestamps = append(r.timestamps, time.Now())
r.timestamps = append(r.timestamps, res.timestamp)
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions runner/reporter_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package runner

import (
"context"
"encoding/json"
"testing"
"time"
Expand All @@ -26,3 +27,31 @@ func TestReport_MarshalJSON(t *testing.T) {
expected := `{"date":"2006-01-02T15:04:00-07:00","options":{"insecure":false,"binary":false,"CPUs":0},"count":1000,"total":10000000000,"average":500000000,"fastest":10000000,"slowest":1000000000,"rps":34567.89,"errorDistribution":null,"statusCodeDistribution":null,"latencyDistribution":null,"histogram":null,"details":null}`
assert.Equal(t, expected, string(json))
}

func TestReport_CorrectDetails(t *testing.T) {
callResultsChan := make(chan *callResult)
config, _ := newConfig("call", "host")
reporter := newReporter(callResultsChan, config)

go reporter.Run()

cr1 := callResult{
status: "OK",
duration: time.Millisecond * 100,
err: nil,
timestamp: time.Now(),
}
callResultsChan <- &cr1
cr2 := callResult{
status: "DeadlineExceeded",
duration: time.Millisecond * 500,
err: context.DeadlineExceeded,
timestamp: time.Now(),
}
callResultsChan <- &cr2

report := reporter.Finalize("stop reason", time.Second)
assert.Equal(t, 2, len(report.Details))
assert.Equal(t, ResultDetail{Error: "", Latency: cr1.duration, Status: cr1.status, Timestamp: cr1.timestamp}, report.Details[0])
assert.Equal(t, ResultDetail{Error: cr2.err.Error(), Latency: cr2.duration, Status: cr2.status, Timestamp: cr2.timestamp}, report.Details[1])
}
7 changes: 4 additions & 3 deletions runner/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ const maxResult = 1000000

// result of a call
type callResult struct {
err error
status string
duration time.Duration
err error
status string
duration time.Duration
timestamp time.Time
}

// Requester is used for doing the requests
Expand Down
2 changes: 1 addition & 1 deletion runner/stats_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *statsHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) {
st = s.Code().String()
}

c.results <- &callResult{rpcStats.Error, st, duration}
c.results <- &callResult{rpcStats.Error, st, duration, end}
}
}

Expand Down

0 comments on commit b5753d6

Please sign in to comment.