Skip to content

Commit

Permalink
report: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shazow committed Dec 18, 2019
1 parent 428bb2a commit f54db6d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 9 additions & 3 deletions report.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"sync"
"time"
)

Expand All @@ -14,6 +15,7 @@ type report struct {
// MismatchedResponse is called when a response set does not match across clients
MismatchedResponse func([]Response)

once sync.Once
pendingResponses map[requestID][]Response

requests int // Number of requests
Expand Down Expand Up @@ -103,10 +105,14 @@ func (r *report) handle(resp Response) error {
return nil
}

func (r *report) Serve(ctx context.Context, respCh <-chan Response) error {
if r.pendingResponses == nil {
func (r *report) init() {
r.once.Do(func() {
r.pendingResponses = make(map[requestID][]Response)
}
})
}

func (r *report) Serve(ctx context.Context, respCh <-chan Response) error {
r.init()

r.started = time.Now()
for {
Expand Down
6 changes: 2 additions & 4 deletions report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ func TestReport(t *testing.T) {
t.Fatal(err)
}

r, err := Report(clients)
if err != nil {
t.Fatal(err)
}
r := report{Clients: clients}
r.init()

r.handle(Response{
client: clients[0],
Expand Down

0 comments on commit f54db6d

Please sign in to comment.