mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge pull request #2553 from node-red-hitachi/add-reset-to-batch-node
Add reset feature to batch node
This commit is contained in:
@@ -107,13 +107,18 @@ describe('BATCH node', function() {
|
||||
}
|
||||
}
|
||||
|
||||
function delayed_send(receiver, index, count, delay) {
|
||||
function delayed_send(receiver, index, count, delay, done) {
|
||||
if (index < count) {
|
||||
setTimeout(function() {
|
||||
receiver.receive({payload: index});
|
||||
delayed_send(receiver, index+1, count, delay);
|
||||
delayed_send(receiver, index+1, count, delay, done);
|
||||
}, delay);
|
||||
}
|
||||
else if(index === count) {
|
||||
if (done) {
|
||||
done();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function check_interval(flow, results, delay, done) {
|
||||
@@ -198,10 +203,28 @@ describe('BATCH node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle reset', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "count", count: 2, overlap: 0, interval: 0, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(batchNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var results = [
|
||||
[0, 1],
|
||||
[4, 5]
|
||||
];
|
||||
check_data(n1, n2, results, done);
|
||||
n1.receive({payload:0});
|
||||
n1.receive({payload:1});
|
||||
n1.receive({payload:2});
|
||||
n1.receive({payload:3, reset: true});
|
||||
n1.receive({payload:4});
|
||||
n1.receive({payload:5});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('mode: interval', function() {
|
||||
|
||||
it('should create seq. with interval', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "interval", count: 0, overlap: 0, interval: 1, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
@@ -265,10 +288,29 @@ describe('BATCH node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle reset', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "interval", count: 0, overlap: 0, interval: 1, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(batchNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var results = [
|
||||
[0, 1],
|
||||
[4, 5]
|
||||
];
|
||||
check_data(n1, n2, results, done);
|
||||
delayed_send(n1, 0, 3, 400, function () {
|
||||
setTimeout(function () {
|
||||
n1.receive({payload: "3", reset: true});
|
||||
delayed_send(n1, 4, 7, 400);
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('mode: concat', function() {
|
||||
|
||||
it('should concat two seq. (series)', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "concat", count: 0, overlap: 0, interval: 1, allowEmptySequence: false, topics: [{topic: "TA"}, {topic: "TB"}], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
@@ -355,6 +397,58 @@ describe('BATCH node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle reset', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "concat", count: 0, overlap: 0, interval: 1, allowEmptySequence: false, topics: [{topic: "TA"}, {topic: "TB"}], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
try {
|
||||
helper.load(batchNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var results = [
|
||||
[2, 3, 0, 1]
|
||||
];
|
||||
check_data(n1, n2, results, done);
|
||||
var inputs0 = [
|
||||
["TB", 0, 0, 2],
|
||||
["TA", 1, 0, 2],
|
||||
];
|
||||
for(var data of inputs0) {
|
||||
var msg = {
|
||||
topic: data[0],
|
||||
payload: data[1],
|
||||
parts: {
|
||||
id: data[0],
|
||||
index: data[2],
|
||||
count: data[3]
|
||||
}
|
||||
};
|
||||
n1.receive(msg);
|
||||
}
|
||||
n1.receive({payload: undefined, reset: true});
|
||||
var inputs1 = [
|
||||
["TB", 0, 0, 2],
|
||||
["TB", 1, 1, 2],
|
||||
["TA", 2, 0, 2],
|
||||
["TA", 3, 1, 2]
|
||||
];
|
||||
for(var data of inputs1) {
|
||||
var msg = {
|
||||
topic: data[0],
|
||||
payload: data[1],
|
||||
parts: {
|
||||
id: data[0],
|
||||
index: data[2],
|
||||
count: data[3]
|
||||
}
|
||||
};
|
||||
n1.receive(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user