Skip to content

Commit

Permalink
Fixed Kafka races (#54)
Browse files Browse the repository at this point in the history
* fixed some race conditions
* speed up of uuid short tests
  • Loading branch information
roblaszczak authored and maclav3 committed Feb 22, 2019
1 parent 927c7ae commit 7b6669c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions internal/norace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build !race

package internal

const RaceEnabled = false
5 changes: 5 additions & 0 deletions internal/race.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build race

package internal

const RaceEnabled = true
4 changes: 3 additions & 1 deletion message/infrastructure/kafka/pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"testing"
"time"

"github.com/ThreeDotsLabs/watermill/internal"

"github.com/Shopify/sarama"

"github.com/ThreeDotsLabs/watermill"
Expand Down Expand Up @@ -102,7 +104,7 @@ func TestPublishSubscribe(t *testing.T) {
Persistent: true,
}

if testing.Short() {
if testing.Short() && !internal.RaceEnabled {
// Kafka tests are a bit slow, so let's run only basic test
// todo - speed up
t.Log("Running only TestPublishSubscribe for Kafka with -short flag")
Expand Down
4 changes: 2 additions & 2 deletions message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const (
)

// Equals compare, that two messages are equal. Acks/Nacks are not compared.
func (m Message) Equals(toCompare *Message) bool {
func (m *Message) Equals(toCompare *Message) bool {
if m.UUID != toCompare.UUID {
return false
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func (m *Message) SetContext(ctx context.Context) {

// Copy copies all message without Acks/Nacks.
// The context is not propagated to the copy.
func (m Message) Copy() *Message {
func (m *Message) Copy() *Message {
msg := NewMessage(m.UUID, m.Payload)
msg.Metadata = m.Metadata
return msg
Expand Down
5 changes: 5 additions & 0 deletions uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ func testuUniqness(t *testing.T, genFunc func() string) {
producers := 100
uuidsPerProducer := 10000

if testing.Short() {
producers = 10
uuidsPerProducer = 1000
}

uuidsCount := producers * uuidsPerProducer

uuids := make(chan string, uuidsCount)
Expand Down

0 comments on commit 7b6669c

Please sign in to comment.