Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yash.bansal committed Sep 9, 2024
1 parent 7b8bcb3 commit 4ec781c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
6 changes: 2 additions & 4 deletions pubsub/gochannel/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,10 @@ func (s *subscriber) sendMessageToSubscriber(msg *message.Message, logFields wat
s.sending.Lock()
defer s.sending.Unlock()

var ctx context.Context
ctx := msg.Context()

//This is getting the context from the message, not the subscriber
if s.preserveContext {
ctx = msg.Context()
} else {
if !s.preserveContext {
var cancelCtx context.CancelFunc
ctx, cancelCtx = context.WithCancel(s.ctx)
defer cancelCtx()
Expand Down
10 changes: 2 additions & 8 deletions pubsub/tests/test_asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,11 @@ func AssertMessagesMetadata(t *testing.T, key string, expectedValues map[string]
}

// AssertAllMessagesHaveSameContext checks if context of all received messages is the same as in expectedValues, if PreserveContext is enabled.
func AssertAllMessagesHaveSameContext(t *testing.T, contextKeyString string, expectedValues map[string]context.Context, received []*message.Message) bool {
func AssertAllMessagesHaveSameContext(t *testing.T, contextKeyString string, expectedValues map[string]context.Context, received []*message.Message) {
assert.Len(t, received, len(expectedValues))

ok := true
for _, msg := range received {
expectedValue := expectedValues[msg.UUID].Value(contextKey(contextKeyString)).(string)
actualValue := msg.Context().Value(contextKeyString)
if !assert.Equal(t, expectedValue, actualValue) {
ok = false
}
assert.Equal(t, expectedValue, actualValue)
}

return ok
}

0 comments on commit 4ec781c

Please sign in to comment.