Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
add test case for issue114
Browse files Browse the repository at this point in the history
  • Loading branch information
devigned committed Apr 1, 2019
1 parent ca4ff1d commit 7a413f1
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions subscription_test.go
Expand Up @@ -27,6 +27,7 @@ import (
"encoding/xml"
"fmt"
"strings"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -412,6 +413,56 @@ func (suite *serviceBusSuite) testSubscriptionManager(tests map[string]func(cont
}
}

func (suite *serviceBusSuite) TestSubscription_TwoWithReceiveAndDelete() {
ns := suite.getNewSasInstance()
topicName := suite.randEntityName()
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()

topicCleanup := makeTopic(ctx, suite.T(), ns, topicName)
defer topicCleanup()
topic, err := ns.NewTopic(topicName)
if suite.NoError(err) {
subName1 := suite.randEntityName()
subCleanup1 := makeSubscription(ctx, suite.T(), topic, subName1)
defer subCleanup1()
subName2 := suite.randEntityName()
subCleanup2 := makeSubscription(ctx, suite.T(), topic, subName2)
defer subCleanup2()

sub1, err := topic.NewSubscription(subName1, SubscriptionWithReceiveAndDelete())
suite.Require().NoError(err)

sub2, err := topic.NewSubscription(subName2, SubscriptionWithReceiveAndDelete())
suite.Require().NoError(err)

wg := sync.WaitGroup{}
wg.Add(2)

go func(){
suite.Require().NoError(sub1.ReceiveOne(ctx, HandlerFunc(func(ctx context.Context, msg *Message) error {
wg.Done()
return nil
})))
}()

suite.Require().NoError(topic.Send(ctx, NewMessageFromString("foo")))

go func(){
suite.Require().NoError(sub2.ReceiveOne(ctx, HandlerFunc(func(ctx context.Context, msg *Message) error {
wg.Done()
return nil
})))
}()

suite.Require().NoError(topic.Send(ctx, NewMessageFromString("foo")))

wg.Wait()
suite.NoError(sub1.Close(ctx))
suite.NoError(sub2.Close(ctx))
}
}

func (suite *serviceBusSuite) TestSubscription_WithReceiveAndDelete() {
tests := map[string]func(context.Context, *testing.T, *Topic, *Subscription){
"ReceiveOne": testSubscriptionReceiveOneNoComplete,
Expand Down

0 comments on commit 7a413f1

Please sign in to comment.