Skip to content
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

Rename sender.FailOver() to sender.SetAzSender() #237

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions v2/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,21 @@ func (d *Sender) AzSender() AzServiceBusSender {
return d.sbSender
}

// FailOver sets the underlying azservicebus.Sender instance to the provided one.
// This is used when the traffic needs to be failed over to a different sender instance.
// SetAzSender sets the underlying azservicebus.Sender instance to the provided one.
// All ongoing send operations will continue to use the old sender instance,
// while new send operations will use the new sender instance.
func (d *Sender) FailOver(sender AzServiceBusSender) {
func (d *Sender) SetAzSender(sender AzServiceBusSender) {
d.mu.Lock()
defer d.mu.Unlock()
d.sbSender = sender
}

// Deprecated: use SetAzSender.
// FailOver sets the underlying azservicebus.Sender instance to the provided one.
func (d *Sender) FailOver(sender AzServiceBusSender) {
d.SetAzSender(sender)
}

// SetMessageId sets the ServiceBus message's ID to a user-specified value
func SetMessageId(messageId *string) func(msg *azservicebus.Message) error {
return func(msg *azservicebus.Message) error {
Expand Down
12 changes: 7 additions & 5 deletions v2/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,20 @@ func TestSender_AzSender(t *testing.T) {
g.Expect(sender.AzSender()).To(Equal(azSender))
}

func TestSender_FailOver(t *testing.T) {
func TestSender_SetAzSender(t *testing.T) {
g := NewWithT(t)
azSender := &fakeAzSender{SendMessageErr: fmt.Errorf("msg send failure")}
sender := NewSender(azSender, nil)
err := sender.SendMessage(context.Background(), "test")
g.Expect(err).To(HaveOccurred())
sender.FailOver(&fakeAzSender{})
sender.SetAzSender(&fakeAzSender{})
err = sender.SendMessage(context.Background(), "test")
g.Expect(err).ToNot(HaveOccurred())
// coverage for deprecated FailOver() function
sender.FailOver(&fakeAzSender{})
}

func TestSender_ConcurrentSendAndFailOver(t *testing.T) {
func TestSender_ConcurrentSendAndSetAzSender(t *testing.T) {
g := NewWithT(t)
azSender1 := &fakeAzSender{}
azSender2 := &fakeAzSender{}
Expand All @@ -294,9 +296,9 @@ func TestSender_ConcurrentSendAndFailOver(t *testing.T) {
g.Expect(err).ToNot(HaveOccurred())
}(i)
}
// call FailOver in the middle
// call SetAzSender in the middle
time.Sleep(5 * time.Millisecond)
sender.FailOver(azSender2)
sender.SetAzSender(azSender2)
// wait for all goroutines to finish
wg.Wait()
// check that some messages were sent with the first sender and some with the second
Expand Down
Loading