-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_test.go
51 lines (43 loc) · 912 Bytes
/
queue_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package mqueue
import (
"fmt"
"github.com/stretchr/testify/assert"
"log"
"testing"
"time"
)
func getQueue() (Queue, error) {
queue, err := New(Config{
Name: "Test",
Url: "amqp://test:[email protected]:5672/test-vhost",
Driver: "rabbit",
})
if err != nil {
panic(err)
}
return queue, err
}
func TestNew(t *testing.T) {
var err error
queue, _ := getQueue()
queue.EnableLog(true)
var send = func(i int) error {
message := fmt.Sprintf("%d message", i)
log.Println(fmt.Sprintf("Send a message: %s", message))
return queue.Delay([]byte(message), "1000")
}
err = queue.Receive(func(body []byte) {
log.Println(fmt.Sprintf("Received:%s\n", string(body)))
})
assert.NoError(t, err)
go func() {
for i := 0; ; i++ {
err := send(i)
assert.NoError(t, err)
time.Sleep(3 * time.Second)
}
}()
//time.Sleep(10 * time.Second)
forever := make(chan bool)
<-forever
}