-
Notifications
You must be signed in to change notification settings - Fork 21
/
groups_test.go
65 lines (56 loc) · 1.2 KB
/
groups_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
package tasqueue
import (
"context"
"testing"
"time"
)
func TestEnqueueGroup(t *testing.T) {
var (
ctx = context.Background()
srv = newServer(t, taskName, MockHandler)
group = makeGroup(t, false, false)
)
go srv.Start(ctx)
id, err := srv.EnqueueGroup(ctx, group)
if err != nil {
t.Fatal(err)
}
t.Logf("Enqueued job with id : %s\n", id)
}
func TestGetGroup(t *testing.T) {
var (
groups = map[string]Group{
StatusDone: makeGroup(t, false, false),
StatusFailed: makeGroup(t, true, true),
}
srv = newServer(t, taskName, MockHandler)
ctx = context.Background()
)
go srv.Start(ctx)
for status, group := range groups {
id, err := srv.EnqueueGroup(ctx, group)
if err != nil {
t.Fatal(err)
}
// Wait for task to be consumed & processed.
time.Sleep(time.Second)
msg, err := srv.GetGroup(ctx, id)
if err != nil {
t.Fatal(err)
}
if msg.Status != status {
t.Fatalf("incorrect job status, expected %s, got %s", status, msg.Status)
}
}
}
func makeGroup(t *testing.T, fs ...bool) Group {
var jobs []Job
for _, f := range fs {
jobs = append(jobs, makeJob(t, taskName, f))
}
grp, err := NewGroup(jobs, GroupOpts{})
if err != nil {
t.Fatal(err)
}
return grp
}