This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
forked from contribsys/faktory_worker_go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner_test.go
105 lines (83 loc) · 2.94 KB
/
runner_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package faktory_worker
import (
"context"
"log"
"math/rand"
"os"
"testing"
faktory "github.com/contribsys/faktory/client"
"github.com/stretchr/testify/assert"
)
func sometask(ctx context.Context, args ...interface{}) error {
return nil
}
func TestRegistration(t *testing.T) {
t.Parallel()
mgr := NewManager()
mgr.Register("somejob", sometask)
}
func TestWeightedQueues(t *testing.T) {
rand.Seed(42)
mgr := NewManager()
mgr.ProcessWeightedPriorityQueues(map[string]int{"critical": 3, "default": 2, "bulk": 1})
assert.Equal(t, []string{"critical", "default", "bulk"}, mgr.queueList())
assert.Equal(t, []string{"bulk", "default", "critical"}, mgr.queueList())
mgr.ProcessWeightedPriorityQueues(map[string]int{"critical": 1, "default": 100, "bulk": 1000})
assert.Equal(t, []string{"bulk", "default", "critical"}, mgr.queueList())
mgr.ProcessWeightedPriorityQueues(map[string]int{"critical": 1, "default": 1000, "bulk": 100})
assert.Equal(t, []string{"default", "bulk", "critical"}, mgr.queueList())
mgr.ProcessWeightedPriorityQueues(map[string]int{"critical": 1, "default": 1, "bulk": 1})
assert.Equal(t, []string{"critical", "bulk", "default"}, mgr.queueList())
}
func TestStrictQueues(t *testing.T) {
t.Parallel()
mgr := NewManager()
mgr.ProcessStrictPriorityQueues("critical", "default", "bulk")
assert.Equal(t, []string{"critical", "default", "bulk"}, mgr.queueList())
assert.Equal(t, []string{"critical", "default", "bulk"}, mgr.queueList())
assert.Equal(t, []string{"critical", "default", "bulk"}, mgr.queueList())
assert.Equal(t, []string{"critical", "default", "bulk"}, mgr.queueList())
mgr.ProcessStrictPriorityQueues("default", "critical", "bulk")
assert.Equal(t, []string{"default", "critical", "bulk"}, mgr.queueList())
assert.Equal(t, []string{"default", "critical", "bulk"}, mgr.queueList())
assert.Equal(t, []string{"default", "critical", "bulk"}, mgr.queueList())
assert.Equal(t, []string{"default", "critical", "bulk"}, mgr.queueList())
}
func TestLiveServer(t *testing.T) {
mgr := NewManager()
mgr.ProcessStrictPriorityQueues("fwgtest")
mgr.Concurrency = 1
mgr.setUpWorkerProcess()
mgr.Register("aworker", func(ctx context.Context, args ...interface{}) error {
//fmt.Println("doing work", args)
return nil
})
withServer(t, "oss", mgr, func(cl *faktory.Client) error {
cl.Flush()
j := faktory.NewJob("something", 1, 2)
j.Queue = "fwgtest"
err := cl.Push(j)
assert.NoError(t, err)
err = processOne(mgr)
assert.Error(t, err)
_, ok := err.(*NoHandlerError)
assert.True(t, ok)
assert.Equal(t, err, &NoHandlerError{JobType: "something"})
j = faktory.NewJob("aworker", 1, 2)
j.Queue = "fwgtest"
err = cl.Push(j)
assert.NoError(t, err)
err = processOne(mgr)
assert.NoError(t, err)
return nil
})
}
func TestThreadDump(t *testing.T) {
t.Parallel()
devnull, err := os.OpenFile("/dev/null", os.O_WRONLY, 0)
assert.NoError(t, err)
logg := &StdLogger{
log.New(devnull, "", 0),
}
dumpThreads(logg)
}