1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Ensure trigger sends complete 2nd msg if set to send latest msg

and add test
to close #2474
This commit is contained in:
Dave Conway-Jones 2020-02-24 21:17:54 +00:00
parent 54978e4d64
commit 8405826fab
No known key found for this signature in database
GPG Key ID: 302A6725C594817F
2 changed files with 13 additions and 8 deletions

View File

@ -106,7 +106,9 @@ module.exports = function(RED) {
});
}
var npay;
this.on('input', function(msg) {
if (node.op2type === "payl") { npay = RED.util.cloneMessage(msg); }
processMessageQueue(msg);
});
@ -124,7 +126,7 @@ module.exports = function(RED) {
else {
if (((!node.topics[topic].tout) && (node.topics[topic].tout !== 0)) || (node.loop === true)) {
promise = Promise.resolve();
if (node.op2type === "pay" || node.op2type === "payl") { node.topics[topic].m2 = RED.util.cloneMessage(msg.payload); }
if (node.op2type === "pay") { node.topics[topic].m2 = RED.util.cloneMessage(msg.payload); }
else if (node.op2Templated) { node.topics[topic].m2 = mustache.render(node.op2,msg); }
else if (node.op2type !== "nul") {
promise = new Promise((resolve,reject) => {
@ -188,7 +190,8 @@ module.exports = function(RED) {
promise.then(() => {
msg2.payload = node.topics[topic].m2;
delete node.topics[topic];
node.send(msg2);
if (node.op2type === "payl") { node.send(npay); }
else { node.send(msg2); }
node.status({});
}).catch(err => {
node.error(err);
@ -244,9 +247,9 @@ module.exports = function(RED) {
});
}, node.duration);
}
else {
if (node.op2type === "payl") { node.topics[topic].m2 = RED.util.cloneMessage(msg.payload); }
}
// else {
// if (node.op2type === "payl") {node.topics[topic].m2 = RED.util.cloneMessage(msg.payload); }
// }
}
return Promise.resolve();
}

View File

@ -736,10 +736,12 @@ describe('trigger node', function() {
try {
if (c === 0) {
msg.should.have.a.property("payload", "Goodbye");
msg.should.have.a.property("topic", "test2");
c += 1;
}
else {
msg.should.have.a.property("payload", "World");
msg.should.have.a.property("topic", "test3");
(Date.now() - ss).should.be.greaterThan(70);
done();
}
@ -747,12 +749,12 @@ describe('trigger node', function() {
catch(err) { done(err); }
});
var ss = Date.now();
n1.emit("input", {payload:"Hello"});
n1.emit("input", {payload:"Hello", topic:"test1"});
setTimeout( function() {
n1.emit("input", {payload:"Goodbye"});
n1.emit("input", {payload:"Goodbye", topic:"test2"});
},20);
setTimeout( function() {
n1.emit("input", {payload:"World"});
n1.emit("input", {payload:"World", topic:"test3"});
},80);
});
});