-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrq_test.go
More file actions
50 lines (40 loc) · 945 Bytes
/
rq_test.go
File metadata and controls
50 lines (40 loc) · 945 Bytes
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
package queue
import (
"encoding/json"
"fmt"
"math/rand"
"testing"
"time"
rds "github.com/redis/go-redis/v9"
)
type msg struct {
Name string `json:"name"`
Age int `json:"age"`
}
func TestRdsQueue(t *testing.T) {
client := rds.NewClient(&rds.Options{Addr: "localhost:6379", Password: "", DB: 0})
count, size := int32(0), 8
topic := "belike"
q := NewRdsQueue(client)
q.AddTopic(topic, func(name string, batch batchEntry) error {
for _, e := range batch.entries {
count += 1
var m msg
err := json.Unmarshal(([]byte)(e.Data.(string)), &m)
if err != nil {
return err
}
}
return nil
}, stdHandleErr)
go q.Consume(topic)
for i := 0; i < size; i++ {
q.Produce(topic, Entry{Key: "", Data: msg{Name: fmt.Sprintf("msg[%d]", i), Age: rand.Intn(100)}})
}
timer := time.NewTimer(time.Second * 3)
<-timer.C
q.Wait()
if count != int32(size) {
t.Errorf("count: %d, expected: %d", count, size)
}
}