Add unit tests for Join restartTimeout and update help

This commit is contained in:
Nick O'Leary 2021-09-30 10:59:45 +01:00
parent 5df0dae11a
commit ec27e19e3f
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 33 additions and 1 deletions

View File

@ -93,6 +93,10 @@
<dt class="optional">complete</dt>
<dd>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.</dd>
<dt class="optional">reset</dt>
<dd>If set, the node will clear any partially complete message and not send it.</dd>
<dt class="optional">restartTimeout</dt>
<dd>If set, and the node has a timeout configured, that timeout will be restarted.</dd>
</dl>
<h3>Details</h3>
@ -115,7 +119,8 @@
<p>A <i>count</i> 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.</p>
<p>A <i>timeout</i> 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 <code>msg.restartTimeout</code> property set.</p>
<p>A <i>timeout</i> 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 <code>msg.restartTimeout</code> property set.</p>
<p>If a message is received with the <code>msg.complete</code> property set, the output message is finalised and sent.
This resets any part counts.</p>
<p>If a message is received with the <code>msg.reset</code> property set, the partly complete message is deleted and not sent.

View File

@ -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"}];