From ec27e19e3fc8e47d3adcaeba310f611e4befb67b Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 30 Sep 2021 10:59:45 +0100 Subject: [PATCH] Add unit tests for Join restartTimeout and update help --- .../locales/en-US/sequence/17-split.html | 7 ++++- test/nodes/core/sequence/17-split_spec.js | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/nodes/locales/en-US/sequence/17-split.html b/packages/node_modules/@node-red/nodes/locales/en-US/sequence/17-split.html index 4884c96da..95d99a086 100644 --- a/packages/node_modules/@node-red/nodes/locales/en-US/sequence/17-split.html +++ b/packages/node_modules/@node-red/nodes/locales/en-US/sequence/17-split.html @@ -93,6 +93,10 @@
complete
If set, the node will append the payload, and then send the output message in its current state. If you don't wish to append the payload, delete it from the msg.
+
reset
+
If set, the node will clear any partially complete message and not send it.
+
restartTimeout
+
If set, and the node has a timeout configured, that timeout will be restarted.

Details

@@ -115,7 +119,8 @@

A count can be set for how many messages should be received before generating the output message. For object outputs, once this count has been reached, the node can be configured to send a message for each subsequent message received.

-

A timeout can be set to trigger sending the new message using whatever has been received so far. This timeout can be restarted and set to its initial value by sending a message with the msg.restartTimeout property set.

+

A timeout can be set to trigger sending the new message using whatever has been received so far. + This timeout can be restarted by sending a message with the msg.restartTimeout property set.

If a message is received with the msg.complete property set, the output message is finalised and sent. This resets any part counts.

If a message is received with the msg.reset property set, the partly complete message is deleted and not sent. diff --git a/test/nodes/core/sequence/17-split_spec.js b/test/nodes/core/sequence/17-split_spec.js index 18ee8b299..370e0cda4 100644 --- a/test/nodes/core/sequence/17-split_spec.js +++ b/test/nodes/core/sequence/17-split_spec.js @@ -798,6 +798,33 @@ describe('JOIN node', function() { }); }); + it('should allow the timeout to be restarted', function(done) { + var flow = [{id:"n1", type:"join", wires:[["n2"]], build:"string", timeout:0.5, count:"", joiner:",",mode:"custom"}, + {id:"n2", type:"helper"}]; + helper.load(joinNode, flow, function() { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + n2.on("input", function(msg) { + try { + msg.should.have.property("payload"); + msg.payload.should.equal("a,b,c"); + const timeTaken = (Date.now() - start)/1000; + // Node times out after 0.5s. + // It receives a restartTimeout after 0.4s. + // So time taken to timeout should be approx 0.9 + timeTaken.should.be.approximately(0.9,0.15); + done(); + } + catch(e) { done(e) } + }); + var start = Date.now(); + n1.receive({payload:"a"}); + setTimeout(function() { + n1.receive({payload:"b", restartTimeout: true}); + n1.receive({payload:"c"}); + },400); + }); + }); it('should join strings with a specifed character and complete when told to', function(done) { var flow = [{id:"n1", type:"join", wires:[["n2"]], build:"string", timeout:5, count:0, joiner:"\n",mode:"custom"}, {id:"n2", type:"helper"}];