Skip to content

Commit

Permalink
Fix flaky TestJetStreamConcurrentQueueDurablePushConsumers test (#1267)
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
  • Loading branch information
piotrpio committed May 19, 2023
1 parent 2c5733a commit 7c468cd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions js_test.go
Expand Up @@ -537,20 +537,22 @@ func TestJetStreamConcurrentQueueDurablePushConsumers(t *testing.T) {
}

// Now create 10 durables concurrently.
subs := make(chan *Subscription, 10)
subs := make([]*Subscription, 0, 10)
var wg sync.WaitGroup
mx := &sync.Mutex{}

for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()
sub, _ := js.QueueSubscribeSync("foo", "bar")
subs <- sub
mx.Lock()
subs = append(subs, sub)
mx.Unlock()
}()
}
// Wait for all the consumers.
wg.Wait()
close(subs)

si, err := js.StreamInfo("TEST")
if err != nil {
Expand All @@ -570,7 +572,7 @@ func TestJetStreamConcurrentQueueDurablePushConsumers(t *testing.T) {
got := 0
for time.Now().Before(timeout) {
got = 0
for sub := range subs {
for _, sub := range subs {
pending, _, _ := sub.Pending()
// If a single sub has the total, then probably something is not right.
if pending == total {
Expand Down

0 comments on commit 7c468cd

Please sign in to comment.