Join: reduce fails if count not in first msg received

This commit is contained in:
Nick O'Leary 2018-07-26 14:13:12 +01:00
parent 9efd48fe51
commit 52f74ff7e0
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 30 additions and 3 deletions

View File

@ -335,9 +335,8 @@ module.exports = function(RED) {
}
var group = pending[gid];
var msgs = group.msgs;
if(parts.hasOwnProperty('count') &&
(group.count === undefined)) {
group.count = count;
if(parts.hasOwnProperty('count') && (group.count === undefined)) {
group.count = parts.count;
}
msgs.push(msg);
pending_count++;

View File

@ -956,6 +956,34 @@ describe('JOIN node', function() {
});
});
it('should reduce messages - count only in last part', function(done) {
var flow = [{id:"n1", type:"join", mode:"reduce",
reduceRight:false,
reduceExp:"$A+payload",
reduceInit:"0",
reduceInitType:"num",
reduceFixup:undefined,
wires:[["n2"]]},
{id:"n2", type:"helper"}];
helper.load(joinNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var count = 0;
n2.on("input", function(msg) {
try {
msg.should.have.property("payload");
msg.payload.should.equal(10);
done();
}
catch(e) { done(e); }
});
n1.receive({payload:3, parts:{index:2, id:222}});
n1.receive({payload:2, parts:{index:1, id:222}});
n1.receive({payload:4, parts:{index:3, count:4,id:222}});
n1.receive({payload:1, parts:{index:0, id:222}});
});
});
function checkInitTypes(itype, ival, rval, initializer, checker, done) {
var flow = [{id:"n1", z:"f0", type:"join", mode:"reduce",
reduceRight:false,