-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #275 #276
Open
upils
wants to merge
3
commits into
ThreeDotsLabs:master
Choose a base branch
from
upils:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix #275 #276
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -108,6 +108,72 @@ func TestPublishSubscribe_block_until_ack(t *testing.T) { | |
} | ||
} | ||
|
||
func TestPublishSubscribe_do_not_block_without_ack_required(t *testing.T) { | ||
Comment on lines
110
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use a small function name to make it more concise? |
||
t.Helper() | ||
|
||
messagesCount := 10 | ||
subscribersCount := 10 | ||
|
||
pubSub := gochannel.NewGoChannel( | ||
gochannel.Config{ | ||
OutputChannelBuffer: int64(messagesCount), | ||
Persistent: true, | ||
}, | ||
watermill.NewStdLogger(true, false), | ||
) | ||
|
||
allSent := sync.WaitGroup{} | ||
allSent.Add(messagesCount) | ||
allReceived := sync.WaitGroup{} | ||
|
||
sentMessages := message.Messages{} | ||
subscriberReceivedCh := make(chan message.Messages, subscribersCount) | ||
for i := 0; i < subscribersCount; i++ { | ||
allReceived.Add(1) | ||
|
||
go func(i int) { | ||
allMsgReceived := make(message.Messages, 0) | ||
msgs, err := pubSub.Subscribe(context.Background(), "topic") | ||
require.NoError(t, err) | ||
|
||
for received := range msgs { | ||
allMsgReceived = append(allMsgReceived, received) | ||
if len(allMsgReceived) >= len(sentMessages) { | ||
break | ||
} | ||
} | ||
subscriberReceivedCh <- allMsgReceived | ||
allReceived.Done() | ||
}(i) | ||
} | ||
|
||
go func() { | ||
for i := 0; i < messagesCount; i++ { | ||
msg := message.NewMessage(watermill.NewUUID(), nil) | ||
sentMessages = append(sentMessages, msg) | ||
|
||
go func() { | ||
require.NoError(t, pubSub.Publish("topic", msg)) | ||
allSent.Done() | ||
}() | ||
} | ||
}() | ||
|
||
log.Println("waiting for all sent") | ||
allSent.Wait() | ||
|
||
log.Println("waiting for all received") | ||
allReceived.Wait() | ||
|
||
close(subscriberReceivedCh) | ||
|
||
log.Println("asserting") | ||
|
||
for subMsgs := range subscriberReceivedCh { | ||
tests.AssertAllMessagesReceived(t, sentMessages, subMsgs) | ||
} | ||
} | ||
|
||
func TestPublishSubscribe_race_condition_on_subscribe(t *testing.T) { | ||
testsCount := 15 | ||
if testing.Short() { | ||
|
@@ -228,19 +294,6 @@ func testPublishSubscribeSubRace(t *testing.T) { | |
allSent.Add(messagesCount) | ||
allReceived := sync.WaitGroup{} | ||
|
||
sentMessages := message.Messages{} | ||
go func() { | ||
for i := 0; i < messagesCount; i++ { | ||
msg := message.NewMessage(watermill.NewUUID(), nil) | ||
sentMessages = append(sentMessages, msg) | ||
|
||
go func() { | ||
require.NoError(t, pubSub.Publish("topic", msg)) | ||
allSent.Done() | ||
}() | ||
} | ||
}() | ||
|
||
subscriberReceivedCh := make(chan message.Messages, subscribersCount) | ||
for i := 0; i < subscribersCount; i++ { | ||
allReceived.Add(1) | ||
|
@@ -256,6 +309,19 @@ func testPublishSubscribeSubRace(t *testing.T) { | |
}() | ||
} | ||
|
||
sentMessages := message.Messages{} | ||
go func() { | ||
for i := 0; i < messagesCount; i++ { | ||
msg := message.NewMessage(watermill.NewUUID(), nil) | ||
sentMessages = append(sentMessages, msg) | ||
|
||
go func() { | ||
require.NoError(t, pubSub.Publish("topic", msg)) | ||
allSent.Done() | ||
}() | ||
} | ||
}() | ||
|
||
log.Println("waiting for all sent") | ||
allSent.Wait() | ||
|
||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The select below isn't really blocking execution, as it's running in another goroutine.
BlockPublishUntilSubscriberAck
is checked inPublish
and that's where it blocks.Can you share more about your use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m110 the current implementation will cause deadlock on all subscribers even if one of them did Ack/Nack a message. However I believe only the subscriber that does not Ack/Nack should lose the message leaving the rest processing goes through. So the setting to block publishing will deadlock if one subscriber does not Ack and I don't think that the intention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion will be to timeout when the
BlockPublishUntilSubscriberAck
is set to avoid the deadlock. That means when an Ack/Nack is not received after some time for a given subscriber the message is lost because the timeout will kick in and the context will be cancelled.