mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
f96ce2fd83
commit
5012568464
@ -308,6 +308,17 @@ class Flow {
|
|||||||
removedMap[id] = true;
|
removedMap[id] = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let nodesToStop = [];
|
||||||
|
let configsToStop = [];
|
||||||
|
stopList.forEach(id => {
|
||||||
|
if (this.flow.configs[id]) {
|
||||||
|
configsToStop.push(id);
|
||||||
|
} else {
|
||||||
|
nodesToStop.push(id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
stopList = nodesToStop.concat(configsToStop);
|
||||||
|
|
||||||
var promises = [];
|
var promises = [];
|
||||||
for (i=0;i<stopList.length;i++) {
|
for (i=0;i<stopList.length;i++) {
|
||||||
var node = this.activeNodes[stopList[i]];
|
var node = this.activeNodes[stopList[i]];
|
||||||
|
@ -404,7 +404,15 @@ function stop(type,diff,muteLog) {
|
|||||||
|
|
||||||
events.emit("flows:stopping",{config: activeConfig, type: type, diff: diff})
|
events.emit("flows:stopping",{config: activeConfig, type: type, diff: diff})
|
||||||
|
|
||||||
for (var id in activeFlows) {
|
// Stop the global flow object last
|
||||||
|
let activeFlowIds = Object.keys(activeFlows);
|
||||||
|
let globalIndex = activeFlowIds.indexOf("global");
|
||||||
|
if (globalIndex !== -1) {
|
||||||
|
activeFlowIds.splice(globalIndex,1);
|
||||||
|
activeFlowIds.push("global");
|
||||||
|
}
|
||||||
|
|
||||||
|
activeFlowIds.forEach(id => {
|
||||||
if (activeFlows.hasOwnProperty(id)) {
|
if (activeFlows.hasOwnProperty(id)) {
|
||||||
var flowStateChanged = diff && (diff.added.indexOf(id) !== -1 || diff.removed.indexOf(id) !== -1);
|
var flowStateChanged = diff && (diff.added.indexOf(id) !== -1 || diff.removed.indexOf(id) !== -1);
|
||||||
log.debug("red/nodes/flows.stop : stopping flow : "+id);
|
log.debug("red/nodes/flows.stop : stopping flow : "+id);
|
||||||
@ -413,7 +421,7 @@ function stop(type,diff,muteLog) {
|
|||||||
delete activeFlows[id];
|
delete activeFlows[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return Promise.all(promises).then(function() {
|
return Promise.all(promises).then(function() {
|
||||||
for (id in activeNodesToFlow) {
|
for (id in activeNodesToFlow) {
|
||||||
|
@ -34,6 +34,7 @@ describe('Flow', function() {
|
|||||||
var getType;
|
var getType;
|
||||||
|
|
||||||
var stoppedNodes = {};
|
var stoppedNodes = {};
|
||||||
|
var stoppedOrder = [];
|
||||||
var currentNodes = {};
|
var currentNodes = {};
|
||||||
var rewiredNodes = {};
|
var rewiredNodes = {};
|
||||||
var createCount = 0;
|
var createCount = 0;
|
||||||
@ -41,6 +42,7 @@ describe('Flow', function() {
|
|||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
currentNodes = {};
|
currentNodes = {};
|
||||||
stoppedNodes = {};
|
stoppedNodes = {};
|
||||||
|
stoppedOrder =[];
|
||||||
rewiredNodes = {};
|
rewiredNodes = {};
|
||||||
createCount = 0;
|
createCount = 0;
|
||||||
Flow.init({settings:{},log:{
|
Flow.init({settings:{},log:{
|
||||||
@ -71,6 +73,7 @@ describe('Flow', function() {
|
|||||||
this.on('close',function() {
|
this.on('close',function() {
|
||||||
node.stopped = true;
|
node.stopped = true;
|
||||||
stoppedNodes[node.id] = node;
|
stoppedNodes[node.id] = node;
|
||||||
|
stoppedOrder.push(node.id)
|
||||||
delete currentNodes[node.id];
|
delete currentNodes[node.id];
|
||||||
});
|
});
|
||||||
this.__updateWires = this.updateWires;
|
this.__updateWires = this.updateWires;
|
||||||
@ -99,6 +102,7 @@ describe('Flow', function() {
|
|||||||
this.on('close',function() {
|
this.on('close',function() {
|
||||||
node.stopped = true;
|
node.stopped = true;
|
||||||
stoppedNodes[node.id] = node;
|
stoppedNodes[node.id] = node;
|
||||||
|
stoppedOrder.push(node.id)
|
||||||
delete currentNodes[node.id];
|
delete currentNodes[node.id];
|
||||||
});
|
});
|
||||||
this.__updateWires = this.updateWires;
|
this.__updateWires = this.updateWires;
|
||||||
@ -131,6 +135,7 @@ describe('Flow', function() {
|
|||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
node.stopped = true;
|
node.stopped = true;
|
||||||
stoppedNodes[node.id] = node;
|
stoppedNodes[node.id] = node;
|
||||||
|
stoppedOrder.push(node.id)
|
||||||
delete currentNodes[node.id];
|
delete currentNodes[node.id];
|
||||||
done();
|
done();
|
||||||
},node.closeDelay);
|
},node.closeDelay);
|
||||||
@ -159,6 +164,7 @@ describe('Flow', function() {
|
|||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
node.stopped = true;
|
node.stopped = true;
|
||||||
stoppedNodes[node.id] = node;
|
stoppedNodes[node.id] = node;
|
||||||
|
stoppedOrder.push(node.id)
|
||||||
delete currentNodes[node.id];
|
delete currentNodes[node.id];
|
||||||
done();
|
done();
|
||||||
},node.closeDelay);
|
},node.closeDelay);
|
||||||
@ -461,6 +467,34 @@ describe('Flow', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("stops config nodes last",function(done) {
|
||||||
|
var config = flowUtils.parseConfig([
|
||||||
|
{id:"t1",type:"tab"},
|
||||||
|
{id:"1",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["2"]},
|
||||||
|
{id:"c1",z:"t1",type:"test"},
|
||||||
|
{id:"2",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["3"]},
|
||||||
|
{id:"c2",z:"t1",type:"test"},
|
||||||
|
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"a",wires:[]},
|
||||||
|
{id:"c3",z:"t1",type:"test"}
|
||||||
|
]);
|
||||||
|
var flow = Flow.create({},config,config.flows["t1"]);
|
||||||
|
flow.start();
|
||||||
|
|
||||||
|
currentNodes.should.have.a.property("1");
|
||||||
|
currentNodes.should.have.a.property("2");
|
||||||
|
currentNodes.should.have.a.property("3");
|
||||||
|
currentNodes.should.have.a.property("c1");
|
||||||
|
currentNodes.should.have.a.property("c2");
|
||||||
|
currentNodes.should.have.a.property("c3");
|
||||||
|
stoppedOrder.should.have.a.length(0);
|
||||||
|
|
||||||
|
flow.stop().then(function() {
|
||||||
|
stoppedOrder.should.eql([ '1', '2', '3', 'c1', 'c2', 'c3' ]);
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it("Times out a node that fails to close", function(done) {
|
it("Times out a node that fails to close", function(done) {
|
||||||
Flow.init({settings:{nodeCloseTimeout:50},log:{
|
Flow.init({settings:{nodeCloseTimeout:50},log:{
|
||||||
log: sinon.stub(),
|
log: sinon.stub(),
|
||||||
|
Loading…
Reference in New Issue
Block a user