-
Notifications
You must be signed in to change notification settings - Fork 1
/
mutate_multi_test.go
106 lines (83 loc) · 2.32 KB
/
mutate_multi_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
106
package quirk
import (
"context"
"sync"
"testing"
"time"
"github.com/cheggaaa/pb/v3"
"github.com/dgraph-io/dgo/v2"
. "github.com/franela/goblin"
)
func TestMutateMulti(t *testing.T) {
g := Goblin(t)
c := NewClient()
g.Describe("mutateMulti", func() {
ctx := context.Background()
g.It("Should not error", func() {
g.Assert(c.mutateMulti(ctx,
dgo.NewDgraphClient(&testDgraphClient{}), []interface{}{},
make(map[string]UID), c.mutateSingleStruct)).
Equal(nil)
})
})
}
func TestLaunchWorkers(t *testing.T) {
g := Goblin(t)
g.Describe("mutateMultiStruct", func() {
var (
done = make(chan error)
quit = make(chan bool)
)
g.It("should not error", func() {
g.Assert(launchWorkers(0, &pb.ProgressBar{}, done, quit)).
Equal(nil)
})
})
}
func TestMutationWorker(t *testing.T) {
g := Goblin(t)
g.Describe("mutation worker", func() {
var (
m sync.Mutex
mSS = NewClient(WithPredicateKey("username")).mutateSingleStruct
ctx = context.Background()
api = &testDgraphClient{queryResponse: []byte("{}")}
dg = dgo.NewDgraphClient(api)
logger = NewNilLogger()
uidMap = make(map[string]UID)
done = make(chan error, 1)
)
g.It("should not error when new", func() {
read := make(chan interface{})
quit := make(chan bool)
api.shouldAbort = false
// oof that's a lot of parameters...
// Hello past self, don't worry I got your back covered.
pkg := &workerPackage{dg, &m, mSS, logger, &pb.ProgressBar{}}
go mutationWorker(ctx, pkg, uidMap, read, quit, done)
// So then the logging if statement passes.
time.Sleep(200 * time.Millisecond)
close(quit)
time.Sleep(100 * time.Millisecond)
read <- &testPersonCorrect
read <- &testPersonCorrect
close(read)
})
g.It("should not error when old", func() {
read := make(chan interface{})
quit := make(chan bool)
api.shouldAbort = true
// oof that's a lot of parameters...
// Hello past self, don't worry I got your back covered.
pkg := &workerPackage{dg, &m, mSS, logger, &pb.ProgressBar{}}
go mutationWorker(ctx, pkg, uidMap, read, quit, done)
read <- &testPersonCorrect
// So then the set to false won't come in too early.
time.Sleep(100 * time.Millisecond)
api.shouldAbort = false
close(read)
err := <-done
g.Assert(err).Equal(nil)
})
})
}