mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add more Flow_spec tests
This commit is contained in:
@@ -18,7 +18,11 @@
|
||||
var should = require("should");
|
||||
var sinon = require('sinon');
|
||||
var clone = require('clone');
|
||||
var util = require("util");
|
||||
|
||||
var Flow = require("../../../red/nodes/Flow");
|
||||
var flows = require("../../../red/nodes/flows");
|
||||
var Node = require("../../../red/nodes/Node");
|
||||
|
||||
var typeRegistry = require("../../../red/nodes/registry");
|
||||
var credentials = require("../../../red/nodes/credentials");
|
||||
@@ -216,8 +220,10 @@ describe('Flow', function() {
|
||||
});
|
||||
|
||||
it('identifies nodes with changed properties, including downstream linked', function() {
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = [{id:"1",type:"test",foo:"b",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = clone(config);
|
||||
newConfig[0].foo = "b";
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
@@ -231,7 +237,9 @@ describe('Flow', function() {
|
||||
|
||||
it('identifies nodes with changed properties, including upstream linked', function() {
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"c",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = clone(config);
|
||||
newConfig[1].bar = "c";
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
@@ -242,10 +250,28 @@ describe('Flow', function() {
|
||||
diffResult.should.have.property("linked",["1"]);
|
||||
diffResult.should.have.property("wiringChanged",[]);
|
||||
});
|
||||
|
||||
it('identifies nodes with changed credentials, including downstream linked', function() {
|
||||
var config = [{id:"1",type:"test",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = clone(config);
|
||||
newConfig[0].credentials = {};
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
var diffResult = flow.diffFlow(newConfig);
|
||||
|
||||
diffResult.should.have.property("deleted",[]);
|
||||
diffResult.should.have.property("changed",["1"]);
|
||||
diffResult.should.have.property("linked",["2"]);
|
||||
diffResult.should.have.property("wiringChanged",[]);
|
||||
});
|
||||
|
||||
it('identifies nodes with changed wiring', function() {
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[2]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = clone(config);
|
||||
newConfig[1].wires[0][0] = 2;
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
@@ -258,8 +284,10 @@ describe('Flow', function() {
|
||||
});
|
||||
|
||||
it('identifies nodes with changed wiring - second connection added', function() {
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1],[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = clone(config);
|
||||
newConfig[1].wires[0].push([1]);
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
@@ -271,9 +299,11 @@ describe('Flow', function() {
|
||||
diffResult.should.have.property("wiringChanged",["2"]);
|
||||
});
|
||||
|
||||
it('identifies nodes with changed wiring - second connection removed', function() {
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1],[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
it('identifies nodes with changed wiring - second connection added', function() {
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = clone(config);
|
||||
newConfig[1].wires[0].push([1]);
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
@@ -284,10 +314,28 @@ describe('Flow', function() {
|
||||
diffResult.should.have.property("linked",["1","2"]);
|
||||
diffResult.should.have.property("wiringChanged",["2"]);
|
||||
});
|
||||
|
||||
it('identifies nodes with changed wiring - node connected', function() {
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:[["2"]]},{id:"2",type:"test",bar:"b",wires:[[]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = clone(config);
|
||||
newConfig[1].wires.push("3");
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
var diffResult = flow.diffFlow(newConfig);
|
||||
|
||||
diffResult.should.have.property("deleted",[]);
|
||||
diffResult.should.have.property("changed",[]);
|
||||
diffResult.should.have.property("linked",["1","2","3"]);
|
||||
diffResult.should.have.property("wiringChanged",["2"]);
|
||||
});
|
||||
|
||||
it('identifies new nodes', function() {
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = clone(config);
|
||||
newConfig.push({id:"2",type:"test",bar:"b",wires:[[1]]});
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
@@ -301,7 +349,10 @@ describe('Flow', function() {
|
||||
|
||||
it('identifies deleted nodes', function() {
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:[[2]]},{id:"2",type:"test",bar:"b",wires:[[3]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = [{id:"1",type:"test",foo:"a",wires:[]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = clone(config);
|
||||
newConfig.splice(1,1);
|
||||
newConfig[0].wires = [];
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
@@ -312,5 +363,459 @@ describe('Flow', function() {
|
||||
diffResult.should.have.property("linked",["1","3"]);
|
||||
diffResult.should.have.property("wiringChanged",["1"]);
|
||||
});
|
||||
|
||||
it('identifies config nodes changes', function() {
|
||||
var config = [{id:"1",type:"test",foo:"configNode",wires:[[2]]},{id:"2",type:"test",bar:"b",wires:[[3]]},{id:"3",type:"test",foo:"a",wires:[]},{id:"configNode",type:"testConfig"}];
|
||||
var newConfig = clone(config);
|
||||
newConfig[3].foo = "bar";
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
var diffResult = flow.diffFlow(newConfig);
|
||||
|
||||
diffResult.should.have.property("deleted",[]);
|
||||
diffResult.should.have.property("changed",["1","configNode"]);
|
||||
diffResult.should.have.property("linked",["2","3"]);
|
||||
diffResult.should.have.property("wiringChanged",[]);
|
||||
});
|
||||
|
||||
it('marks a parent subflow as changed for an internal property change', function() {
|
||||
var config = [
|
||||
{id:"1",type:"test",wires:[[2]]},
|
||||
{id:"2",type:"subflow:sf1",wires:[[3]]},
|
||||
{id:"3",type:"test",wires:[]},
|
||||
{id:"sf1",type:"subflow"},
|
||||
{id:"sf1-1",z:"sf1",type:"test",foo:"a"},
|
||||
{id:"4",type:"subflow:sf1"}
|
||||
];
|
||||
|
||||
var newConfig = clone(config);
|
||||
newConfig[4].foo = "b";
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
var diffResult = flow.diffFlow(newConfig);
|
||||
|
||||
diffResult.should.have.property("deleted",[]);
|
||||
diffResult.should.have.property("changed",["2","4"]);
|
||||
diffResult.should.have.property("linked",["1","3"]);
|
||||
diffResult.should.have.property("wiringChanged",[]);
|
||||
});
|
||||
|
||||
it('marks a parent subflow as changed for an internal wiring change', function() {
|
||||
var config = [
|
||||
{id:"1",type:"test",wires:[[2]]},
|
||||
{id:"2",type:"subflow:sf1",wires:[[3]]},
|
||||
{id:"3",type:"test",wires:[]},
|
||||
{id:"sf1",type:"subflow"},
|
||||
{id:"sf1-1",z:"sf1",type:"test"},
|
||||
{id:"sf1-2",z:"sf1",type:"test"}
|
||||
];
|
||||
|
||||
var newConfig = clone(config);
|
||||
newConfig[4].wires = [["sf1-2"]];
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
var diffResult = flow.diffFlow(newConfig);
|
||||
|
||||
diffResult.should.have.property("deleted",[]);
|
||||
diffResult.should.have.property("changed",["2"]);
|
||||
diffResult.should.have.property("linked",["1","3"]);
|
||||
diffResult.should.have.property("wiringChanged",[]);
|
||||
});
|
||||
it('marks a parent subflow as changed for an internal node delete', function() {
|
||||
var config = [
|
||||
{id:"1",type:"test",wires:[[2]]},
|
||||
{id:"2",type:"subflow:sf1",wires:[[3]]},
|
||||
{id:"3",type:"test",wires:[]},
|
||||
{id:"sf1",type:"subflow"},
|
||||
{id:"sf1-1",z:"sf1",type:"test"},
|
||||
{id:"sf1-2",z:"sf1",type:"test"}
|
||||
];
|
||||
|
||||
var newConfig = clone(config);
|
||||
newConfig.splice(5,1);
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
var diffResult = flow.diffFlow(newConfig);
|
||||
|
||||
diffResult.should.have.property("deleted",[]);
|
||||
diffResult.should.have.property("changed",["2"]);
|
||||
diffResult.should.have.property("linked",["1","3"]);
|
||||
diffResult.should.have.property("wiringChanged",[]);
|
||||
});
|
||||
it('marks a parent subflow as changed for an internal subflow wiring change - input removed', function() {
|
||||
var config = [
|
||||
{id:"1",type:"test",wires:[[2]]},
|
||||
{id:"2",type:"subflow:sf1",wires:[[3]]},
|
||||
{id:"3",type:"test",wires:[]},
|
||||
{id:"sf1",type:"subflow","in": [{"wires": [{"id": "sf1-1"}]}],"out": [{"wires": [{"id": "sf1-2","port": 0}]}]},
|
||||
{id:"sf1-1",z:"sf1",type:"test"},
|
||||
{id:"sf1-2",z:"sf1",type:"test"}
|
||||
];
|
||||
|
||||
var newConfig = clone(config);
|
||||
newConfig[3].in[0].wires = [];
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
var diffResult = flow.diffFlow(newConfig);
|
||||
|
||||
diffResult.should.have.property("deleted",[]);
|
||||
diffResult.should.have.property("changed",["2"]);
|
||||
diffResult.should.have.property("linked",["1","3"]);
|
||||
diffResult.should.have.property("wiringChanged",[]);
|
||||
});
|
||||
it('marks a parent subflow as changed for an internal subflow wiring change - input added', function() {
|
||||
var config = [
|
||||
{id:"1",type:"test",wires:[[2]]},
|
||||
{id:"2",type:"subflow:sf1",wires:[[3]]},
|
||||
{id:"3",type:"test",wires:[]},
|
||||
{id:"sf1",type:"subflow","in": [{"wires": [{"id": "sf1-1"}]}],"out": [{"wires": [{"id": "sf1-2","port": 0}]}]},
|
||||
{id:"sf1-1",z:"sf1",type:"test"},
|
||||
{id:"sf1-2",z:"sf1",type:"test"}
|
||||
];
|
||||
|
||||
var newConfig = clone(config);
|
||||
newConfig[3].in[0].wires.push({"id":"sf1-2"});
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
var diffResult = flow.diffFlow(newConfig);
|
||||
|
||||
diffResult.should.have.property("deleted",[]);
|
||||
diffResult.should.have.property("changed",["2"]);
|
||||
diffResult.should.have.property("linked",["1","3"]);
|
||||
diffResult.should.have.property("wiringChanged",[]);
|
||||
});
|
||||
|
||||
it('marks a parent subflow as changed for an internal subflow wiring change - output added', function() {
|
||||
var config = [
|
||||
{id:"1",type:"test",wires:[[2]]},
|
||||
{id:"2",type:"subflow:sf1",wires:[[3]]},
|
||||
{id:"3",type:"test",wires:[]},
|
||||
{id:"sf1",type:"subflow","in": [{"wires": [{"id": "sf1-1"}]}],"out": [{"wires": [{"id": "sf1-2","port": 0}]}]},
|
||||
{id:"sf1-1",z:"sf1",type:"test"},
|
||||
{id:"sf1-2",z:"sf1",type:"test"}
|
||||
];
|
||||
|
||||
var newConfig = clone(config);
|
||||
newConfig[3].out[0].wires.push({"id":"sf1-2","port":0});
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
var diffResult = flow.diffFlow(newConfig);
|
||||
|
||||
diffResult.should.have.property("deleted",[]);
|
||||
diffResult.should.have.property("changed",["2"]);
|
||||
diffResult.should.have.property("linked",["1","3"]);
|
||||
diffResult.should.have.property("wiringChanged",[]);
|
||||
});
|
||||
|
||||
it('marks a parent subflow as changed for an internal subflow wiring change - output removed', function() {
|
||||
var config = [
|
||||
{id:"1",type:"test",wires:[[2]]},
|
||||
{id:"2",type:"subflow:sf1",wires:[[3]]},
|
||||
{id:"3",type:"test",wires:[]},
|
||||
{id:"sf1",type:"subflow","in": [{"wires": [{"id": "sf1-1"}]}],"out": [{"wires": [{"id": "sf1-2","port": 0}]}]},
|
||||
{id:"sf1-1",z:"sf1",type:"test"},
|
||||
{id:"sf1-2",z:"sf1",type:"test"}
|
||||
];
|
||||
|
||||
var newConfig = clone(config);
|
||||
newConfig[3].out[0].wires = [];
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.getMissingTypes().should.have.length(0);
|
||||
|
||||
var diffResult = flow.diffFlow(newConfig);
|
||||
|
||||
diffResult.should.have.property("deleted",[]);
|
||||
diffResult.should.have.property("changed",["2"]);
|
||||
diffResult.should.have.property("linked",["1","3"]);
|
||||
diffResult.should.have.property("wiringChanged",[]);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('#applyConfig',function() {
|
||||
var getType;
|
||||
var getNode;
|
||||
var flowsAdd;
|
||||
var credentialsClean;
|
||||
|
||||
var stoppedNodes = {};
|
||||
var currentNodes = {};
|
||||
|
||||
var TestNode = function(n) {
|
||||
Node.call(this,n);
|
||||
var node = this;
|
||||
this.handled = 0;
|
||||
this.stopped = false;
|
||||
this.on('input',function(msg) {
|
||||
node.handled++;
|
||||
node.send(msg);
|
||||
});
|
||||
this.on('close',function() {
|
||||
node.stopped = true;
|
||||
stoppedNodes[node.id] = node;
|
||||
delete currentNodes[node.id];
|
||||
});
|
||||
}
|
||||
util.inherits(TestNode,Node);
|
||||
|
||||
|
||||
|
||||
|
||||
before(function() {
|
||||
flowsAdd = sinon.stub(flows,"add",function(node) {
|
||||
currentNodes[node.id] = node;
|
||||
});
|
||||
getNode = sinon.stub(flows,"get",function(id) {
|
||||
return currentNodes[id];
|
||||
});
|
||||
getType = sinon.stub(typeRegistry,"get",function(type) {
|
||||
return TestNode;
|
||||
});
|
||||
credentialsClean = sinon.stub(credentials,"clean",function(config){});
|
||||
|
||||
});
|
||||
after(function() {
|
||||
getType.restore();
|
||||
flowsAdd.restore();
|
||||
credentialsClean.restore();
|
||||
getNode.restore();
|
||||
});
|
||||
|
||||
beforeEach(function() {
|
||||
currentNodes = {};
|
||||
stoppedNodes = {};
|
||||
});
|
||||
|
||||
it("instantiates an initial configuration and stops it",function(done) {
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:["2"]},{id:"2",type:"test",bar:"b",wires:[["3"]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.start();
|
||||
|
||||
currentNodes.should.have.a.property("1");
|
||||
currentNodes.should.have.a.property("2");
|
||||
currentNodes.should.have.a.property("3");
|
||||
|
||||
currentNodes["1"].should.have.a.property("handled",0);
|
||||
currentNodes["2"].should.have.a.property("handled",0);
|
||||
currentNodes["3"].should.have.a.property("handled",0);
|
||||
|
||||
|
||||
currentNodes["1"].receive({payload:"test"});
|
||||
|
||||
currentNodes["1"].should.have.a.property("handled",1);
|
||||
currentNodes["2"].should.have.a.property("handled",1);
|
||||
currentNodes["3"].should.have.a.property("handled",1);
|
||||
|
||||
flow.stop().then(function() {
|
||||
currentNodes.should.not.have.a.property("1");
|
||||
currentNodes.should.not.have.a.property("2");
|
||||
currentNodes.should.not.have.a.property("3");
|
||||
stoppedNodes.should.have.a.property("1");
|
||||
stoppedNodes.should.have.a.property("2");
|
||||
stoppedNodes.should.have.a.property("3");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("stops all nodes on new full deploy",function(done) {
|
||||
var config = [{id:"1",type:"test",foo:"a",wires:["2"]},{id:"2",type:"test",bar:"b",wires:[["3"]]},{id:"3",type:"test",foo:"a",wires:[]}];
|
||||
var newConfig = [{id:"4",type:"test",foo:"a",wires:["5"]},{id:"5",type:"test",bar:"b",wires:[["6"]]},{id:"6",type:"test",foo:"a",wires:[]}];
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.start();
|
||||
|
||||
currentNodes.should.have.a.property("1");
|
||||
currentNodes.should.have.a.property("2");
|
||||
currentNodes.should.have.a.property("3");
|
||||
|
||||
flow.applyConfig(newConfig).then(function() {
|
||||
currentNodes.should.not.have.a.property("1");
|
||||
currentNodes.should.not.have.a.property("2");
|
||||
currentNodes.should.not.have.a.property("3");
|
||||
stoppedNodes.should.have.a.property("1");
|
||||
stoppedNodes.should.have.a.property("2");
|
||||
stoppedNodes.should.have.a.property("3");
|
||||
|
||||
currentNodes.should.have.a.property("4");
|
||||
currentNodes.should.have.a.property("5");
|
||||
currentNodes.should.have.a.property("6");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("stops only modified nodes on 'nodes' deploy",function(done) {
|
||||
var config = [{id:"1",type:"test",name:"a",wires:["2"]},{id:"2",type:"test",name:"b",wires:[["3"]]},{id:"3",type:"test",name:"c",wires:[]}];
|
||||
var newConfig = clone(config);
|
||||
newConfig[1].name = "B";
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.start();
|
||||
|
||||
currentNodes.should.have.a.property("1");
|
||||
currentNodes.should.have.a.property("2");
|
||||
currentNodes.should.have.a.property("3");
|
||||
currentNodes["2"].should.have.a.property("name","b");
|
||||
|
||||
currentNodes["1"].receive({payload:"test"});
|
||||
currentNodes["1"].should.have.a.property("handled",1);
|
||||
currentNodes["2"].should.have.a.property("handled",1);
|
||||
currentNodes["3"].should.have.a.property("handled",1);
|
||||
|
||||
|
||||
flow.applyConfig(newConfig,"nodes").then(function() {
|
||||
currentNodes.should.have.a.property("1");
|
||||
currentNodes.should.have.a.property("2");
|
||||
currentNodes.should.have.a.property("3");
|
||||
currentNodes["2"].should.have.a.property("name","B");
|
||||
|
||||
stoppedNodes.should.not.have.a.property("1");
|
||||
stoppedNodes.should.have.a.property("2");
|
||||
stoppedNodes.should.not.have.a.property("3");
|
||||
stoppedNodes["2"].should.have.a.property("name","b");
|
||||
|
||||
|
||||
currentNodes["1"].receive({payload:"test"});
|
||||
currentNodes["1"].should.have.a.property("handled",2);
|
||||
currentNodes["2"].should.have.a.property("handled",1);
|
||||
currentNodes["3"].should.have.a.property("handled",2);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("stops only modified flows on 'flows' deploy",function(done) {
|
||||
var config = [{id:"1",type:"test",name:"a",wires:["2"]},{id:"2",type:"test",name:"b",wires:[[]]},{id:"3",type:"test",name:"c",wires:[]}];
|
||||
var newConfig = clone(config);
|
||||
newConfig[1].name = "B";
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.start();
|
||||
|
||||
currentNodes.should.have.a.property("1");
|
||||
currentNodes.should.have.a.property("2");
|
||||
currentNodes.should.have.a.property("3");
|
||||
currentNodes["2"].should.have.a.property("name","b");
|
||||
|
||||
currentNodes["1"].receive({payload:"test"});
|
||||
currentNodes["1"].should.have.a.property("handled",1);
|
||||
currentNodes["2"].should.have.a.property("handled",1);
|
||||
currentNodes["3"].should.have.a.property("handled",0);
|
||||
|
||||
currentNodes["3"].receive({payload:"test"});
|
||||
currentNodes["3"].should.have.a.property("handled",1);
|
||||
|
||||
flow.applyConfig(newConfig,"flows").then(function() {
|
||||
currentNodes.should.have.a.property("1");
|
||||
currentNodes.should.have.a.property("2");
|
||||
currentNodes.should.have.a.property("3");
|
||||
currentNodes["2"].should.have.a.property("name","B");
|
||||
|
||||
stoppedNodes.should.have.a.property("1");
|
||||
stoppedNodes.should.have.a.property("2");
|
||||
stoppedNodes.should.not.have.a.property("3");
|
||||
|
||||
stoppedNodes["2"].should.have.a.property("name","b");
|
||||
|
||||
currentNodes["1"].receive({payload:"test"});
|
||||
currentNodes["1"].should.have.a.property("handled",1);
|
||||
currentNodes["2"].should.have.a.property("handled",1);
|
||||
|
||||
currentNodes["3"].receive({payload:"test"});
|
||||
currentNodes["3"].should.have.a.property("handled",2);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("rewires otherwise unmodified nodes on 'nodes' deploy",function(done) {
|
||||
var config = [{id:"1",type:"test",name:"a",wires:["2"]},{id:"2",type:"test",name:"b",wires:[[]]},{id:"3",type:"test",name:"c",wires:[]}];
|
||||
var newConfig = clone(config);
|
||||
newConfig[1].wires[0].push("3");
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.start();
|
||||
|
||||
currentNodes.should.have.a.property("1");
|
||||
currentNodes.should.have.a.property("2");
|
||||
currentNodes.should.have.a.property("3");
|
||||
|
||||
currentNodes["1"].receive({payload:"test"});
|
||||
currentNodes["1"].should.have.a.property("handled",1);
|
||||
currentNodes["2"].should.have.a.property("handled",1);
|
||||
currentNodes["3"].should.have.a.property("handled",0);
|
||||
|
||||
flow.applyConfig(newConfig,"nodes").then(function() {
|
||||
currentNodes.should.have.a.property("1");
|
||||
currentNodes.should.have.a.property("2");
|
||||
currentNodes.should.have.a.property("3");
|
||||
|
||||
stoppedNodes.should.not.have.a.property("1");
|
||||
stoppedNodes.should.not.have.a.property("2");
|
||||
stoppedNodes.should.not.have.a.property("3");
|
||||
|
||||
currentNodes["1"].receive({payload:"test"});
|
||||
currentNodes["1"].should.have.a.property("handled",2);
|
||||
currentNodes["2"].should.have.a.property("handled",2);
|
||||
currentNodes["3"].should.have.a.property("handled",1);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("stops rewired but otherwise unmodified nodes on 'flows' deploy",function(done) {
|
||||
var config = [{id:"1",type:"test",name:"a",wires:["2"]},{id:"2",type:"test",name:"b",wires:[[]]},{id:"3",type:"test",name:"c",wires:[]}];
|
||||
var newConfig = clone(config);
|
||||
newConfig[1].wires[0].push("3");
|
||||
|
||||
var flow = new Flow(config);
|
||||
flow.start();
|
||||
|
||||
currentNodes.should.have.a.property("1");
|
||||
currentNodes.should.have.a.property("2");
|
||||
currentNodes.should.have.a.property("3");
|
||||
|
||||
currentNodes["1"].receive({payload:"test"});
|
||||
currentNodes["1"].should.have.a.property("handled",1);
|
||||
currentNodes["2"].should.have.a.property("handled",1);
|
||||
currentNodes["3"].should.have.a.property("handled",0);
|
||||
|
||||
flow.applyConfig(newConfig,"flows").then(function() {
|
||||
currentNodes.should.have.a.property("1");
|
||||
currentNodes.should.have.a.property("2");
|
||||
currentNodes.should.have.a.property("3");
|
||||
|
||||
stoppedNodes.should.have.a.property("1");
|
||||
stoppedNodes.should.have.a.property("2");
|
||||
stoppedNodes.should.have.a.property("3");
|
||||
|
||||
currentNodes["1"].receive({payload:"test"});
|
||||
currentNodes["1"].should.have.a.property("handled",1);
|
||||
currentNodes["2"].should.have.a.property("handled",1);
|
||||
currentNodes["3"].should.have.a.property("handled",1);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user