Skip to content

Commit

Permalink
making test publisher threadsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
jprobinson committed Jun 20, 2018
1 parent eb0da8c commit 6691aba
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pubsub/pubsubtest/pub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pubsubtest

import (
"errors"
"sync"

"github.com/NYTimes/gizmo/pubsub"
"github.com/golang/protobuf/proto"
Expand All @@ -14,6 +15,7 @@ type (
TestPublisher struct {
// Published will contain a list of all messages that have been published.
Published []TestPublishMsg
pmu sync.Mutex

// GivenError will be returned by the TestPublisher on publish.
// Good for testing error scenarios.
Expand Down Expand Up @@ -44,6 +46,8 @@ func (t *TestPublisher) Publish(ctx context.Context, key string, msg proto.Messa

// PublishRaw publishes the raw message byte slice.
func (t *TestPublisher) PublishRaw(_ context.Context, key string, msg []byte) error {
t.pmu.Lock()
defer t.pmu.Unlock()
t.Published = append(t.Published, TestPublishMsg{key, msg})
return t.GivenError
}
Expand Down

0 comments on commit 6691aba

Please sign in to comment.