-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient-single_test.go
76 lines (56 loc) · 2.48 KB
/
client-single_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 gearman // import "github.com/nathanaelle/gearman/v2"
import (
"context"
"testing"
"github.com/nathanaelle/gearman/v2/protocol"
)
func TestSingleClient_simple(t *testing.T) {
end, cancel := context.WithCancel(context.Background())
defer cancel()
srv := connTest()
defer srv.Close()
//logger := log.New(os.Stderr, "logger: ", log.Lshortfile|log.Ltime)
cli := SingleServerClient(end, nil) //logger)
cli.AddServers(srv)
r := cli.Submit(NewTask("reverse", []byte("test")))
clientSrv(srv, "H:lap:000", "test", "tset", t)
if !validResult(t, []byte("tset"), nil)(r.Value()) {
return
}
}
func TestSingleClient_unordered_result(t *testing.T) {
end, cancel := context.WithCancel(context.Background())
defer cancel()
srv := connTest()
defer srv.Close()
//logger := log.New(os.Stderr, "logger: ", log.Lshortfile|log.Ltime)
cli := SingleServerClient(end, nil) //logger)
cli.AddServers(srv)
r1 := cli.Submit(NewTask("reverse", []byte("test 1")))
r2 := cli.Submit(NewTask("reverse", []byte("test 2")))
r3 := cli.Submit(NewTask("reverse", []byte("test 3")))
if !validStep(t, srv.Received(), protocol.BuildPacket(protocol.SubmitJob, protocol.Opacify([]byte("reverse")), protocol.Opacify([]byte("")), protocol.Opacify([]byte("test 1")))) {
return
}
if !validStep(t, srv.Received(), protocol.BuildPacket(protocol.SubmitJob, protocol.Opacify([]byte("reverse")), protocol.Opacify([]byte("")), protocol.Opacify([]byte("test 2")))) {
return
}
if !validStep(t, srv.Received(), protocol.BuildPacket(protocol.SubmitJob, protocol.Opacify([]byte("reverse")), protocol.Opacify([]byte("")), protocol.Opacify([]byte("test 3")))) {
return
}
srv.Send(protocol.BuildPacket(protocol.JobCreated, protocol.Opacify([]byte("H:lap:1"))))
srv.Send(protocol.BuildPacket(protocol.JobCreated, protocol.Opacify([]byte("H:lap:2"))))
srv.Send(protocol.BuildPacket(protocol.JobCreated, protocol.Opacify([]byte("H:lap:3"))))
srv.Send(protocol.BuildPacket(protocol.WorkComplete, protocol.Opacify([]byte("H:lap:2")), protocol.Opacify([]byte("2 tset"))))
srv.Send(protocol.BuildPacket(protocol.WorkComplete, protocol.Opacify([]byte("H:lap:3")), protocol.Opacify([]byte("3 tset"))))
srv.Send(protocol.BuildPacket(protocol.WorkComplete, protocol.Opacify([]byte("H:lap:1")), protocol.Opacify([]byte("1 tset"))))
if !validResult(t, []byte("3 tset"), nil)(r3.Value()) {
return
}
if !validResult(t, []byte("2 tset"), nil)(r2.Value()) {
return
}
if !validResult(t, []byte("1 tset"), nil)(r1.Value()) {
return
}
}