-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_test.go
56 lines (54 loc) · 1.02 KB
/
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
52
53
54
55
56
package mfworker
import (
"github.com/iflamed/mfworker/job"
"log"
"strconv"
"testing"
"time"
)
func TestNewQueue(t *testing.T) {
var (
count uint
maxItems uint
)
count = 4
maxItems = 16
path := "./test.db"
q := NewQueue(count, maxItems, path, "mfworker", nil)
q.Handler("Test", func(job *job.Job) {
time.Sleep(time.Second)
log.Printf("the job name %s, job body %s ", job.Name, job.Payload)
})
q.Start()
go func() {
for i := 0; i < 64; i++ {
job := &job.Job{
Name: "Test",
Payload: []byte("body " + strconv.Itoa(i)),
}
if (i % 2) != 0 {
job.Id = strconv.Itoa(i)
}
q.Dispatch(job)
}
var jobs []*job.Job
for i := 0; i < 64; i++ {
job := &job.Job{
Name: "Test",
Payload: []byte("body " + strconv.Itoa(i)),
}
if (i % 2) != 0 {
job.Id = strconv.Itoa(i)
}
jobs = append(jobs, job)
}
q.DispatchJobs(jobs)
num := q.CountPendingJobs()
if num <= 0 {
t.Errorf("Queue jobs should not empty.")
}
}()
<-time.After(10 * time.Second)
q.Stop()
return
}