Skip to content

Commit

Permalink
Fix consumer ID issue
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislas-m committed Mar 31, 2018
1 parent 146e7ae commit 63508bb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion amqpw.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/gobuffalo/buffalo/worker"
"github.com/markbates/going/defaults"
"github.com/markbates/going/randx"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/streadway/amqp"
Expand Down Expand Up @@ -140,7 +141,7 @@ func (q *Adapter) Register(name string, h worker.Handler) error {

msgs, err := q.Channel.Consume(
name,
q.consumerName,
fmt.Sprintf("%s_%s_%s", q.consumerName, name, randx.String(20)),
false, // auto-ack
false, // exclusive
false, // no-local
Expand Down
32 changes: 32 additions & 0 deletions amqpw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package amqpw

import (
"context"
"fmt"
"log"
"os"
"sync"
Expand Down Expand Up @@ -66,6 +67,7 @@ func TestMain(m *testing.M) {
}

func Test_Perform(t *testing.T) {
fmt.Println("Test_Perform")
r := require.New(t)

var hit bool
Expand All @@ -83,7 +85,36 @@ func Test_Perform(t *testing.T) {
r.True(hit)
}

func Test_PerformMultiple(t *testing.T) {
fmt.Println("Test_Perform")
r := require.New(t)

var hitPerform1, hitPerform2 bool
wg := &sync.WaitGroup{}
wg.Add(2)
q.Register("perform1", func(worker.Args) error {
hitPerform1 = true
wg.Done()
return nil
})
q.Register("perform2", func(worker.Args) error {
hitPerform2 = true
wg.Done()
return nil
})
q.Perform(worker.Job{
Handler: "perform1",
})
q.Perform(worker.Job{
Handler: "perform2",
})
wg.Wait()
r.True(hitPerform1)
r.True(hitPerform2)
}

func Test_PerformAt(t *testing.T) {
fmt.Println("Test_PerformAt")
r := require.New(t)

var hit bool
Expand All @@ -102,6 +133,7 @@ func Test_PerformAt(t *testing.T) {
}

func Test_PerformIn(t *testing.T) {
fmt.Println("Test_PerformIn")
r := require.New(t)

var hit bool
Expand Down

0 comments on commit 63508bb

Please sign in to comment.