-
Notifications
You must be signed in to change notification settings - Fork 15
/
bridge_remote_test.go
155 lines (125 loc) · 2.96 KB
/
bridge_remote_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package dingo
import (
"testing"
"github.com/stretchr/testify/suite"
)
type remoteBridgeTestSuite struct {
bridgeTestSuite
brk Broker
bkd Backend
}
func (ts *remoteBridgeTestSuite) SetupTest() {
var err error
ts.bridgeTestSuite.SetupTest()
// broker
ts.brk, err = NewLocalBroker(DefaultConfig(), nil)
ts.Nil(err)
ts.Nil(ts.bg.AttachProducer(ts.brk.(Producer)))
ts.Nil(ts.bg.AttachConsumer(ts.brk.(Consumer), nil))
ts.Nil(ts.brk.(Object).Expect(ObjT.Producer | ObjT.Consumer))
// backend
ts.bkd, err = NewLocalBackend(DefaultConfig(), nil)
ts.Nil(err)
ts.Nil(ts.bg.AttachReporter(ts.bkd.(Reporter)))
ts.Nil(ts.bg.AttachStore(ts.bkd.(Store)))
ts.Nil(ts.bkd.(Object).Expect(ObjT.Reporter | ObjT.Store))
}
func (ts *remoteBridgeTestSuite) TearDownTest() {
ts.Nil(ts.brk.(Object).Close())
ts.Nil(ts.bkd.(Object).Close())
ts.bridgeTestSuite.TearDownTest()
}
func TestBridgeRemoteSuite(t *testing.T) {
suite.Run(t, &remoteBridgeTestSuite{
bridgeTestSuite: bridgeTestSuite{
name: "",
},
})
}
//
// test cases
//
func (ts *remoteBridgeTestSuite) TestReturnFix() {
// register a function, returning float64
ts.Nil(ts.trans.Register(
"ReturnFix",
func() float64 { return 0 },
))
// compose a task
t, err := ts.trans.ComposeTask("ReturnFix", nil, nil)
ts.Nil(err)
// compose a corresponding report
r, err := t.composeReport(Status.Success, []interface{}{int(6)}, nil)
ts.Nil(err)
// attach a reporting channel
reports := make(chan *Report, 10)
ts.Nil(ts.bg.Report("ReturnFix", reports))
// poll the task
outputs, err := ts.bg.Poll(t)
ts.Nil(err)
reports <- r
out, ok := <-outputs
ts.True(ok)
ts.Len(out.Return(), 1)
if len(out.Return()) > 0 {
v, ok := out.Return()[0].(float64)
ts.True(ok)
ts.Equal(float64(6), v)
}
}
func (ts *remoteBridgeTestSuite) TestSendTask() {
var (
bg = newRemoteBridge(ts.trans)
err error
)
defer func() {
ts.Nil(err)
}()
// register a task
err = ts.trans.Register("TestSendTask", func() {})
if err != nil {
return
}
// compose a task
task, err := ts.trans.ComposeTask("TestSendTask", nil, nil)
if err != nil {
return
}
// send it, should fail
ts.NotNil(bg.SendTask(task))
}
func (ts *remoteBridgeTestSuite) TestAddListener() {
bg := newRemoteBridge(ts.trans)
// add a new listener, should fail
tasks, err := bg.AddListener(make(chan *TaskReceipt, 10))
ts.Nil(tasks)
ts.NotNil(err)
}
func (ts *remoteBridgeTestSuite) TestReport() {
bg := newRemoteBridge(ts.trans)
// add a report channel, should fail
ts.NotNil(bg.Report("TestReport", make(chan *Report, 10)))
}
func (ts *remoteBridgeTestSuite) TestPoll() {
var (
bg = newRemoteBridge(ts.trans)
err error
)
defer func() {
ts.Nil(err)
}()
// register a task
err = ts.trans.Register("TestPoll", func() {})
if err != nil {
return
}
// compose a task
task, err := ts.trans.ComposeTask("TestPoll", nil, nil)
if err != nil {
return
}
// poll it, should fail
reports, err2 := bg.Poll(task)
ts.Nil(reports)
ts.NotNil(err2)
}