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
/
context_test.go
71 lines (54 loc) · 1.48 KB
/
context_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
package faktory_worker
import (
"errors"
"regexp"
"testing"
faktory "github.com/contribsys/faktory/client"
"github.com/stretchr/testify/assert"
)
func TestSimpleContext(t *testing.T) {
t.Parallel()
pool, err := faktory.NewPool(1)
assert.NoError(t, err)
job := faktory.NewJob("something", 1, 2)
job.SetCustom("track", 1)
//cl, err := faktory.Open()
//assert.NoError(t, err)
//cl.Push(job)
ctx := jobContext(pool, job)
help := HelperFor(ctx)
assert.Equal(t, help.Jid(), job.Jid)
assert.Empty(t, help.Bid())
assert.Equal(t, "something", help.JobType())
_, ok := ctx.Deadline()
assert.False(t, ok)
//assert.NoError(t, ctx.TrackProgress(45, "Working....", nil))
err = help.Batch(func(b *faktory.Batch) error {
return nil
})
assert.Error(t, err)
assert.True(t, errors.Is(err, NoAssociatedBatchError))
}
func TestBatchContext(t *testing.T) {
t.Parallel()
pool, err := faktory.NewPool(1)
assert.NoError(t, err)
job := faktory.NewJob("something", 1, 2)
job.SetCustom("track", 1)
job.SetCustom("bid", "nosuchbatch")
ctx := jobContext(pool, job)
help := HelperFor(ctx)
assert.Equal(t, help.Jid(), job.Jid)
assert.Equal(t, "nosuchbatch", help.Bid())
assert.Equal(t, "something", help.JobType())
mgr := NewManager()
mgr.Pool = pool
withServer(t, "ent", mgr, func(cl *faktory.Client) error {
err = help.Batch(func(b *faktory.Batch) error {
return nil
})
assert.Error(t, err)
assert.Regexp(t, regexp.MustCompile("No such batch"), err.Error())
return nil
})
}