-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprotocol.coffee
More file actions
187 lines (159 loc) · 8.3 KB
/
protocol.coffee
File metadata and controls
187 lines (159 loc) · 8.3 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# javafbp-runtime - FBP runtime protocol implementation for JavaFBP
# (c) 2014 The Grid
# javafbp-runtime may be freely distributed under the MIT license
utils = require './utils'
fs = require 'fs'
chai = require 'chai'
debug = process.env.JAVAFBP_TESTS_DEBUG?
# Used for checks which cannot be evaluated when running in debug,
# when we don't get the stdout of the runtime for instance.
itSkipDebug = if debug then it.skip else it
port = 3569 # FIXME: use other
describe 'NoFlo runtime API,', () ->
runtime = new utils.RuntimeProcess port, debug
ui = new utils.MockUi port
outfile = null
before (done) ->
runtime.start ->
f = () ->
ui.connect()
ui.on 'connected', () ->
done()
setTimeout f, 1000
after (done) ->
ui.disconnect()
ui.on 'disconnected', () ->
runtime.stop () ->
done()
describe 'startup', ->
it 'should not have produced any errors', ->
chai.expect(runtime.popErrors()).to.eql []
describe 'runtime info', ->
info = null
it 'should be returned on getruntime', (done) ->
ui.send "runtime", "getruntime"
ui.once 'runtime-info-changed', () ->
info = ui.runtimeinfo
chai.expect(info).to.be.an 'object'
done()
it 'type should be "javafbp"', ->
chai.expect(info.type).to.equal "javafbp"
it 'protocol version should be "0.4"', ->
chai.expect(info.version).to.be.a "string"
chai.expect(info.version).to.equal "0.4"
it 'capabilities should include "protocol:component"', ->
chai.expect(info.capabilities).to.be.an "array"
chai.expect((info.capabilities.filter -> 'protocol:component')[0]).to.be.a "string"
it 'capabilities should include "protocol:graph"', ->
chai.expect((info.capabilities.filter -> 'protocol:graph')[0]).to.be.a "string"
describe 'sending component list', ->
it 'should return more than 50 components', (done) ->
@timeout 2000
ui.send "component", "list"
ui.on 'component-added', (name, definition) ->
numberOfComponents = Object.keys(ui.components).length
if numberOfComponents == 50
done()
it 'should contain core/Counter', ->
chai.expect(ui.components['core/Counter']).to.be.an 'object'
describe.skip 'core/Counter component', ->
name = 'core/Counter'
it 'should have a "input" buffer port', ->
input = ui.components['gegl/crop'].inPorts.filter (p) -> p.id == 'input'
chai.expect(input.length).to.equal 1
chai.expect(input[0].type).to.equal "buffer"
it 'should have a "output" buffer port', ->
output = ui.components['gegl/crop'].outPorts.filter (p) -> p.id == 'output'
chai.expect(output.length).to.equal 1
chai.expect(output[0].type).to.equal "buffer"
it 'should also have inports for properties "x", "y", "width" and "height"', ->
c = ui.components['gegl/crop']
chai.expect(Object.keys(c.inPorts).length).to.equal 5
chai.expect((c.inPorts.filter (p) -> p.id == 'width')[0].type).to.equal 'number'
chai.expect((c.inPorts.filter (p) -> p.id == 'height')[0].type).to.equal 'number'
chai.expect((c.inPorts.filter (p) -> p.id == 'x')[0].type).to.equal 'number'
chai.expect((c.inPorts.filter (p) -> p.id == 'y')[0].type).to.equal 'number'
it 'should have default value for properties', ->
c = ui.components['gegl/crop']
chai.expect((c.inPorts.filter (p) -> p.id == 'width')[0].default).to.be.a.number
chai.expect((c.inPorts.filter (p) -> p.id == 'width')[0].default).to.equal 10
chai.expect((c.inPorts.filter (p) -> p.id == 'height')[0].default).to.equal 10
chai.expect((c.inPorts.filter (p) -> p.id == 'x')[0].default).to.equal 0
chai.expect((c.inPorts.filter (p) -> p.id == 'y')[0].default).to.equal 0
it 'should have descriptions value for properties', ->
c = ui.components['gegl/crop']
p = (c.inPorts.filter (p) -> p.id == 'width')[0]
chai.expect(p.description).to.be.a.string
chai.expect(p.description).to.equal "Width"
p = (c.inPorts.filter (p) -> p.id == 'x')[0]
chai.expect(p.description).to.be.a.string
chai.expect(p.description).to.equal "X"
it 'should have icon "fa-crop"', ->
chai.expect(ui.components['gegl/crop'].icon).to.equal 'crop'
it 'should have description', ->
chai.expect(ui.components['gegl/crop'].description).to.equal 'Crop a buffer'
describe 'graph building', ->
graph = 'graph1'
# TODO: verify responses being received
send = (protocol, cmd, pay, g) ->
if graph?
pay.graph = g
ui.send protocol, cmd, pay
ui.graph1 =
send: (cmd, pay) ->
send "graph", cmd, pay, graph
outfile = 'spec/out/count-test.txt'
it 'should not crash', (done) ->
ui.send "graph", "clear", {id: graph}
ui.graph1.send "addnode", {id: 'gen', component: 'examples/GenerateTestData'}
ui.graph1.send "addnode", {id: 'counter', component: 'core/Counter'}
ui.graph1.send "addnode", {id: 'out', component: 'core/WriteFile'}
ui.graph1.send "addedge", {src: {node: 'gen', port: 'out'}, tgt: {node: 'counter', port: 'in'}}
ui.graph1.send "addedge", {src: {node: 'counter', port: 'count'}, tgt: {node: 'out', port: 'in'}}
ui.graph1.send "addinitial", {src: {data: 10}, tgt: {node: 'gen', port: 'count'}}
ui.graph1.send "addinitial", {src: {data: outfile}, tgt: {node: 'out', port: 'destination'}}
ui.send "runtime", "getruntime"
ui.once 'runtime-info-changed', ->
done()
itSkipDebug 'should not have produced any errors', ->
chai.expect(runtime.popErrors()).to.eql []
describe 'starting the network', ->
graph = 'graph1'
it 'should respond with network started', (done) ->
ui.send "network", "start", {graph: graph}
ui.once 'network-running', (running) ->
done() if running
it 'should result in a created TXT file', (done) ->
# TODO:
checkInterval = null
checkExistence = ->
fs.exists outfile, (exists) ->
done() if exists
clearInterval checkInterval
checkInterval = setInterval checkExistence, 50
itSkipDebug 'should not have produced any errors', ->
chai.expect(runtime.popErrors()).to.eql []
describe.skip 'stopping the network', ->
graph = 'graph1'
it 'should respond with network stopped', (done) ->
ui.send "network", "stop", {graph: graph}
ui.once 'network-running', (running) ->
done() if not running
itSkipDebug 'should not have produced any errors', ->
chai.expect(runtime.popErrors()).to.eql []
describe 'graph tear down', ->
it 'should not crash', (done) ->
ui.graph1.send "removenode", {id: 'gen'}
ui.graph1.send "removenode", {id: 'counter'}
ui.graph1.send "removenode", {id: 'out'}
ui.graph1.send "removeedge", {src: {node: 'gen', port: 'out'}, tgt: {node: 'count', port: 'in'}}
ui.graph1.send "removeedge", {src: {node: 'counter', port: 'count'}, tgt: {node: 'out', port: 'in'}}
ui.graph1.send "removeinitial", { tgt: {node: 'gen', port: 'count'} }
ui.graph1.send "removeinitial", { tgt: {node: 'out', port: 'destination'} }
ui.send "runtime", "getruntime"
ui.once 'runtime-info-changed', ->
done()
it.skip 'should give empty graph', (done) ->
# TODO: use getgraph command to verify graph is now empty
it 'should not have produced any errors', ->
chai.expect(runtime.popErrors()).to.eql []