-
Notifications
You must be signed in to change notification settings - Fork 43
/
context_test.go
76 lines (60 loc) · 1.68 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
72
73
74
75
76
package faktory_worker
import (
"context"
"errors"
"regexp"
"testing"
"time"
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, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
ctx = jobContext(ctx, 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.True(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, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
ctx = jobContext(ctx, 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
})
}