Skip to content

Commit

Permalink
Merge ed24bfb into d461a12
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Dec 3, 2017
2 parents d461a12 + ed24bfb commit 3bb4e87
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 9 deletions.
97 changes: 97 additions & 0 deletions spec/ComponentLoader.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,100 @@ describe 'ComponentLoader with a fixture project', ->
l.load 'componentloader/Missing', (err, instance) ->
chai.expect(err).to.be.an 'error'
done()

describe 'ComponentLoader with a fixture project and caching', ->
l = null
fixtureRoot = null
before ->
return @skip() if noflo.isBrowser()
fixtureRoot = path.resolve __dirname, 'fixtures/componentloader'
after (done) ->
return done() if noflo.isBrowser()
manifestPath = path.resolve fixtureRoot, 'fbp.json'
{ unlink } = require 'fs'
unlink manifestPath, done
it 'should be possible to pre-heat the cache file', (done) ->
@timeout 8000
{ exec } = require 'child_process'
exec "node #{path.resolve(__dirname, '../bin/noflo-cache-preheat')}",
cwd: fixtureRoot
, done
it 'should have populated a fbp-manifest file', (done) ->
manifestPath = path.resolve fixtureRoot, 'fbp.json'
{ stat } = require 'fs'
stat manifestPath, (err, stats) ->
return done err if err
chai.expect(stats.isFile()).to.equal true
done()
it 'should be possible to instantiate', ->
l = new noflo.ComponentLoader fixtureRoot,
cache: true
it 'should initially know of no components', ->
chai.expect(l.components).to.be.a 'null'
it 'should not initially be ready', ->
chai.expect(l.ready).to.be.false
it 'should be able to read a list of components', (done) ->
ready = false
l.once 'ready', ->
chai.expect(l.ready).to.equal true
ready = l.ready
l.listComponents (err, components) ->
return done err if err
chai.expect(l.processing).to.equal false
chai.expect(l.components).not.to.be.empty
chai.expect(components).to.equal l.components
chai.expect(l.ready).to.equal true
chai.expect(ready).to.equal true
done()
chai.expect(l.processing).to.equal true
it 'should be able to load a local component', (done) ->
l.load 'componentloader/Output', (err, instance) ->
chai.expect(err).to.be.a 'null'
chai.expect(instance.description).to.equal 'Output stuff'
chai.expect(instance.icon).to.equal 'cloud'
done()
it 'should be able to load a component from a dependency', (done) ->
l.load 'example/Forward', (err, instance) ->
chai.expect(err).to.be.a 'null'
chai.expect(instance.description).to.equal 'Forward stuff'
chai.expect(instance.icon).to.equal 'car'
done()
it 'should be able to load a dynamically registered component from a dependency', (done) ->
l.load 'example/Hello', (err, instance) ->
chai.expect(err).to.be.a 'null'
chai.expect(instance.description).to.equal 'Hello stuff'
chai.expect(instance.icon).to.equal 'bicycle'
done()
it 'should be able to load core Graph component', (done) ->
l.load 'Graph', (err, instance) ->
chai.expect(err).to.be.a 'null'
chai.expect(instance.icon).to.equal 'sitemap'
done()
it 'should fail loading a missing component', (done) ->
l.load 'componentloader/Missing', (err, instance) ->
chai.expect(err).to.be.an 'error'
done()
it 'should fail with missing manifest without discover option', (done) ->
l = new noflo.ComponentLoader fixtureRoot,
cache: true
discover: false
manifest: 'fbp2.json'
l.listComponents (err) ->
chai.expect(err).to.be.an 'error'
done()
it 'should be able to use a custom manifest file', (done) ->
@timeout 8000
manifestPath = path.resolve fixtureRoot, 'fbp2.json'
l = new noflo.ComponentLoader fixtureRoot,
cache: true
discover: true
manifest: 'fbp2.json'
l.listComponents (err, components) ->
return done err if err
chai.expect(l.processing).to.equal false
chai.expect(l.components).not.to.be.empty
done()
it 'should have saved the new manifest', (done) ->
manifestPath = path.resolve fixtureRoot, 'fbp2.json'
{ unlink } = require 'fs'
unlink manifestPath, done
73 changes: 73 additions & 0 deletions spec/Network.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,36 @@ describe 'NoFlo Network', ->
chai.expect(err).to.be.an 'error'
chai.expect(err.message).to.contain 'not found'
done()
describe 'with new edge', ->
before ->
n.loader.components.Split = Split
g.addNode 'A', 'Split'
g.addNode 'B', 'Split'
after ->
g.removeNode 'A'
g.removeNode 'B'
it 'should contain the edge', (done) ->
g.once 'addEdge', ->
setTimeout ->
chai.expect(n.connections).not.to.be.empty
chai.expect(n.connections[0].from).to.eql
process: n.getNode 'A'
port: 'out'
index: undefined
chai.expect(n.connections[0].to).to.eql
process: n.getNode 'B'
port: 'in'
index: undefined
done()
, 10
g.addEdge 'A', 'out', 'B', 'in'
it 'should not contain the edge after removal', (done) ->
g.once 'removeEdge', ->
setTimeout ->
chai.expect(n.connections).to.be.empty
done()
, 10
g.removeEdge 'A', 'out', 'B', 'in'

describe 'with a simple graph', ->
g = null
Expand Down Expand Up @@ -593,3 +623,46 @@ describe 'NoFlo Network', ->
chai.expect(err).to.be.an 'error'
chai.expect(err.message).to.contain 'No process defined for inbound node'
done()
describe 'baseDir setting', ->
it 'should set baseDir based on given graph', ->
g = new noflo.Graph
g.baseDir = root
n = new noflo.Network g
chai.expect(n.baseDir).to.equal root
it 'should fall back to CWD if graph has no baseDir', ->
return @skip() if noflo.isBrowser()
g = new noflo.Graph
n = new noflo.Network g
chai.expect(n.baseDir).to.equal process.cwd()
it 'should set the baseDir for the component loader', ->
g = new noflo.Graph
g.baseDir = root
n = new noflo.Network g
chai.expect(n.baseDir).to.equal root
chai.expect(n.loader.baseDir).to.equal root
describe 'debug setting', ->
n = null
g = null
before (done) ->
g = new noflo.Graph
g.baseDir = root
n = new noflo.Network g
n.loader.listComponents (err, components) ->
return done err if err
n.loader.components.Split = Split
g.addNode 'A', 'Split'
g.addNode 'B', 'Split'
g.addEdge 'A', 'out', 'B', 'in'
n.connect done
it 'should initially have debug enabled', ->
chai.expect(n.getDebug()).to.equal true
it 'should have propagated debug setting to connections', ->
chai.expect(n.connections[0].debug).to.equal n.getDebug()
it 'calling setDebug with same value should be no-op', ->
n.setDebug true
chai.expect(n.getDebug()).to.equal true
chai.expect(n.connections[0].debug).to.equal n.getDebug()
it 'disabling debug should get propagated to connections', ->
n.setDebug false
chai.expect(n.getDebug()).to.equal false
chai.expect(n.connections[0].debug).to.equal n.getDebug()
46 changes: 46 additions & 0 deletions spec/Subgraph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,49 @@ describe 'NoFlo Graph component', ->
return done err if err
sendNext()
return
describe 'event forwarding on parent network', ->
graph = null
network = null
before (done) ->
graph = new noflo.Graph 'main'
graph.baseDir = root
network = new noflo.Network graph
network.loader.listComponents (err) ->
return done err if err
network.loader.components.Split = Split
network.loader.components.Merge = SubgraphMerge
sg = new noflo.Graph 'Subgraph'
sg.addNode 'A', 'Split'
sg.addNode 'B', 'Merge'
sg.addEdge 'A', 'out', 'B', 'in'
sg.addInport 'in', 'A', 'in'
sg.addOutport 'out', 'B', 'out'
network.loader.registerGraph 'foo', 'AB', sg, (err) ->
return done err if err
network.connect done
it 'should instantiate the subgraph when node is added', (done) ->
setTimeout ->
chai.expect(network.processes).not.to.be.empty
chai.expect(network.processes.Sub).to.exist
done()
, 10
graph.addNode 'Sub', 'foo/AB'
graph.addNode 'Split', 'Split'
graph.addEdge 'Sub', 'out', 'Split', 'in'
it 'should be possible to start the graph', (done) ->
network.start done
it 'should forward IP events', (done) ->
network.once 'ip', (ip) ->
chai.expect(ip.id).to.equal 'DATA -> IN Sub()'
chai.expect(ip.type).to.equal 'data'
chai.expect(ip.data).to.equal 'foo'
chai.expect(ip.subgraph).to.be.undefined
network.once 'ip', (ip) ->
chai.expect(ip.id).to.equal 'A() OUT -> IN B()'
chai.expect(ip.type).to.equal 'data'
chai.expect(ip.data).to.equal 'foo'
chai.expect(ip.subgraph).to.eql [
'Sub'
]
done()
graph.addInitial 'foo', 'Sub', 'in'
2 changes: 1 addition & 1 deletion src/lib/ComponentLoader.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ComponentLoader extends EventEmitter
@libraryIcons = {}
@processing = false
@ready = false
@setMaxListeners 0 if typeof @setMaxListeners is 'function'
@setMaxListeners 0

# Get the library prefix for a given module name. This
# is mostly used for generating valid names for namespaced
Expand Down
2 changes: 0 additions & 2 deletions src/lib/InPort.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ class InPort extends BasePort

if options.process
throw new Error 'InPort process callback is deprecated. Please use Process API'
delete options.process

if options.handle
throw new Error 'InPort handle callback is deprecated. Please use Process API'
delete options.handle

super options

Expand Down
8 changes: 3 additions & 5 deletions src/lib/Network.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -464,16 +464,14 @@ class Network extends EventEmitter
return callback new Error "No component defined for node #{node.id}"

unless process.component.isReady()
process.component.setMaxListeners 0 if process.component.setMaxListeners
process.component.setMaxListeners 0
process.component.once "ready", =>
@addDefaults process, callback
return

for key, port of process.component.inPorts.ports
# Attach a socket to any defaulted inPorts as long as they aren't already attached.
# TODO: hasDefault existence check is for backwards compatibility, clean
# up when legacy ports are removed.
if typeof port.hasDefault is 'function' and port.hasDefault() and not port.isAttached()
if port.hasDefault() and not port.isAttached()
socket = internalSocket.createSocket()
socket.setDebug @debug

Expand Down Expand Up @@ -502,7 +500,7 @@ class Network extends EventEmitter
return callback new Error "No component defined for inbound node #{initializer.to.node}"

unless to.component.isReady() or to.component.inPorts[initializer.to.port]
to.component.setMaxListeners 0 if to.component.setMaxListeners
to.component.setMaxListeners 0
to.component.once "ready", =>
@addInitial initializer, callback
return
Expand Down
2 changes: 1 addition & 1 deletion src/lib/loader/NodeJs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ manifestLoader =
options.runtimes = loader.options.runtimes or []
options.runtimes.push 'noflo' if options.runtimes.indexOf('noflo') is -1
options.recursive = if typeof loader.options.recursive is 'undefined' then true else loader.options.recursive
options.manifest = 'fbp.json' unless options.manifest
options.manifest = loader.options.manifest or 'fbp.json'
options

listComponents: (loader, manifestOptions, callback) ->
Expand Down

0 comments on commit 3bb4e87

Please sign in to comment.