-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add context propagation to cqrs component (#62)
- Loading branch information
1 parent
44f4c86
commit a406640
Showing
11 changed files
with
108 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cqrs | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ThreeDotsLabs/watermill/message" | ||
) | ||
|
||
type publisherStub struct { | ||
messages map[string]message.Messages | ||
|
||
mu sync.Mutex | ||
} | ||
|
||
func newPublisherStub() *publisherStub { | ||
return &publisherStub{ | ||
messages: make(map[string]message.Messages), | ||
} | ||
} | ||
|
||
func (*publisherStub) Close() error { | ||
return nil | ||
} | ||
|
||
func (p *publisherStub) Publish(topic string, messages ...*message.Message) error { | ||
p.mu.Lock() | ||
defer p.mu.Unlock() | ||
|
||
p.messages[topic] = append(p.messages[topic], messages...) | ||
|
||
return nil | ||
} | ||
|
||
func TestCommandBus_Send_ContextPropagation(t *testing.T) { | ||
publisher := newPublisherStub() | ||
|
||
commandBus := NewCommandBus(publisher, "whatever", JSONMarshaler{}) | ||
|
||
ctx := context.WithValue(context.Background(), "key", "value") | ||
|
||
err := commandBus.Send(ctx, "message") | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, ctx, publisher.messages["whatever"][0].Context()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cqrs | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestEventBus_Send_ContextPropagation(t *testing.T) { | ||
publisher := newPublisherStub() | ||
|
||
eventBus := NewEventBus(publisher, "whatever", JSONMarshaler{}) | ||
|
||
ctx := context.WithValue(context.Background(), "key", "value") | ||
|
||
err := eventBus.Publish(ctx, "message") | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, ctx, publisher.messages["whatever"][0].Context()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters