Skip to content

Commit

Permalink
Merge pull request #276 from lovoo/fix_tester_codecs
Browse files Browse the repository at this point in the history
Tester: fix concurrent map access
  • Loading branch information
jomaresch authored Oct 16, 2020
2 parents f26d361 + 2a57591 commit 463d31e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tester/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ type Tester struct {
mClients sync.RWMutex
clients map[string]*client

codecs map[string]goka.Codec
mCodecs sync.RWMutex
codecs map[string]goka.Codec

mQueues sync.Mutex
topicQueues map[string]*queue

Expand Down Expand Up @@ -214,6 +216,10 @@ func (tt *Tester) getOrCreateQueue(topic string) *queue {
}

func (tt *Tester) codecForTopic(topic string) goka.Codec {
// lock the access to codecs-map
tt.mCodecs.RLock()
defer tt.mCodecs.RUnlock()

codec, exists := tt.codecs[topic]
if !exists {
panic(fmt.Errorf("no codec for topic %s registered", topic))
Expand All @@ -222,6 +228,10 @@ func (tt *Tester) codecForTopic(topic string) goka.Codec {
}

func (tt *Tester) registerCodec(topic string, codec goka.Codec) {
// lock the access to codecs-map
tt.mCodecs.Lock()
defer tt.mCodecs.Unlock()

// create a queue, we're going to need it anyway
tt.getOrCreateQueue(topic)

Expand Down

0 comments on commit 463d31e

Please sign in to comment.