Stop config nodes after flow nodes

Fixes #2876
This commit is contained in:
Nick O'Leary 2021-02-19 20:44:01 +00:00
parent f96ce2fd83
commit 5012568464
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 55 additions and 2 deletions

View File

@ -308,6 +308,17 @@ class Flow {
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 = [];
for (i=0;i<stopList.length;i++) {
var node = this.activeNodes[stopList[i]];

View File

@ -404,7 +404,15 @@ function stop(type,diff,muteLog) {
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)) {
var flowStateChanged = diff && (diff.added.indexOf(id) !== -1 || diff.removed.indexOf(id) !== -1);
log.debug("red/nodes/flows.stop : stopping flow : "+id);
@ -413,7 +421,7 @@ function stop(type,diff,muteLog) {
delete activeFlows[id];
}
}
}
});
return Promise.all(promises).then(function() {
for (id in activeNodesToFlow) {

View File

@ -34,6 +34,7 @@ describe('Flow', function() {
var getType;
var stoppedNodes = {};
var stoppedOrder = [];
var currentNodes = {};
var rewiredNodes = {};
var createCount = 0;
@ -41,6 +42,7 @@ describe('Flow', function() {
beforeEach(function() {
currentNodes = {};
stoppedNodes = {};
stoppedOrder =[];
rewiredNodes = {};
createCount = 0;
Flow.init({settings:{},log:{
@ -71,6 +73,7 @@ describe('Flow', function() {
this.on('close',function() {
node.stopped = true;
stoppedNodes[node.id] = node;
stoppedOrder.push(node.id)
delete currentNodes[node.id];
});
this.__updateWires = this.updateWires;
@ -99,6 +102,7 @@ describe('Flow', function() {
this.on('close',function() {
node.stopped = true;
stoppedNodes[node.id] = node;
stoppedOrder.push(node.id)
delete currentNodes[node.id];
});
this.__updateWires = this.updateWires;
@ -131,6 +135,7 @@ describe('Flow', function() {
setTimeout(function() {
node.stopped = true;
stoppedNodes[node.id] = node;
stoppedOrder.push(node.id)
delete currentNodes[node.id];
done();
},node.closeDelay);
@ -159,6 +164,7 @@ describe('Flow', function() {
setTimeout(function() {
node.stopped = true;
stoppedNodes[node.id] = node;
stoppedOrder.push(node.id)
delete currentNodes[node.id];
done();
},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) {
Flow.init({settings:{nodeCloseTimeout:50},log:{
log: sinon.stub(),