From f54db6d817e1291f90212e45cbc22ccbd7e8b30b Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Wed, 18 Dec 2019 16:27:30 -0500 Subject: [PATCH] report: Fix tests --- report.go | 12 +++++++++--- report_test.go | 6 ++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/report.go b/report.go index 6e00b15..1b1ed45 100644 --- a/report.go +++ b/report.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "sync" "time" ) @@ -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 @@ -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 { diff --git a/report_test.go b/report_test.go index 944ed4b..d62c146 100644 --- a/report_test.go +++ b/report_test.go @@ -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],