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

Merge pull request #1845 from node-red-hitachi/fix-file-node-test-for-ordering-assumption-of-output-message

Update file node test to cope with occasional failure
This commit is contained in:
Nick O'Leary 2018-07-27 13:20:27 +01:00 committed by GitHub
commit 3ac8ce03bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,9 +46,14 @@ describe('file Nodes', function() {
it('should be loaded', function(done) { it('should be loaded', function(done) {
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":true, "overwriteFile":true}]; var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":true, "overwriteFile":true}];
helper.load(fileNode, flow, function() { helper.load(fileNode, flow, function() {
var fileNode1 = helper.getNode("fileNode1"); try {
fileNode1.should.have.property('name', 'fileNode'); var fileNode1 = helper.getNode("fileNode1");
done(); fileNode1.should.have.property('name', 'fileNode');
done();
}
catch (e) {
done(e);
}
}); });
}); });
@ -59,11 +64,16 @@ describe('file Nodes', function() {
var n1 = helper.getNode("fileNode1"); var n1 = helper.getNode("fileNode1");
var n2 = helper.getNode("helperNode1"); var n2 = helper.getNode("helperNode1");
n2.on("input", function(msg) { n2.on("input", function(msg) {
var f = fs.readFileSync(fileToTest); try {
f.should.have.length(4); var f = fs.readFileSync(fileToTest);
fs.unlinkSync(fileToTest); f.should.have.length(4);
msg.should.have.property("payload", "test"); fs.unlinkSync(fileToTest);
done(); msg.should.have.property("payload", "test");
done();
}
catch (e) {
done(e);
}
}); });
n1.receive({payload:"test"}); n1.receive({payload:"test"});
}); });
@ -83,20 +93,26 @@ describe('file Nodes', function() {
var data = ["test2", true, 999, [2]]; var data = ["test2", true, 999, [2]];
n2.on("input", function (msg) { n2.on("input", function (msg) {
msg.should.have.property("payload", data[count]); try {
if (count === 3) { msg.should.have.property("payload");
var f = fs.readFileSync(fileToTest).toString(); data.should.containDeep([msg.payload]);
if (os.type() !== "Windows_NT") { if (count === 3) {
f.should.have.length(19); var f = fs.readFileSync(fileToTest).toString();
f.should.equal("test2\ntrue\n999\n[2]\n"); if (os.type() !== "Windows_NT") {
} f.should.have.length(19);
else { f.should.equal("test2\ntrue\n999\n[2]\n");
f.should.have.length(23); }
f.should.equal("test2\r\ntrue\r\n999\r\n[2]\r\n"); else {
} f.should.have.length(23);
done(); f.should.equal("test2\r\ntrue\r\n999\r\n[2]\r\n");
} }
count++; done();
}
count++;
}
catch (e) {
done(e);
}
}); });
n1.receive({payload:"test2"}); // string n1.receive({payload:"test2"}); // string
@ -126,31 +142,37 @@ describe('file Nodes', function() {
var count = 0; var count = 0;
n2.on("input", function (msg) { n2.on("input", function (msg) {
msg.should.have.property("payload", data[count]); try {
try { msg.should.have.property("payload");
if (count === 1) { data.should.containDeep([msg.payload]);
// Check they got appended as expected try {
var f = fs.readFileSync(fileToTest).toString(); if (count === 1) {
f.should.equal("onetwo"); // Check they got appended as expected
var f = fs.readFileSync(fileToTest).toString();
f.should.equal("onetwo");
// Delete the file // Delete the file
fs.unlinkSync(fileToTest); fs.unlinkSync(fileToTest);
setTimeout(function() { setTimeout(function() {
// Send two more messages to the file // Send two more messages to the file
n1.receive({payload:"three"}); n1.receive({payload:"three"});
n1.receive({payload:"four"}); n1.receive({payload:"four"});
}, wait); }, wait);
} }
if (count === 3) { if (count === 3) {
var f = fs.readFileSync(fileToTest).toString(); var f = fs.readFileSync(fileToTest).toString();
f.should.equal("threefour"); f.should.equal("threefour");
fs.unlinkSync(fileToTest); fs.unlinkSync(fileToTest);
done(); done();
} }
} catch(err) { } catch(err) {
done(err); done(err);
} }
count++; count++;
}
catch (e) {
done(e);
}
}); });
// Send two messages to the file // Send two messages to the file
@ -174,7 +196,8 @@ describe('file Nodes', function() {
n2.on("input", function (msg) { n2.on("input", function (msg) {
try { try {
msg.should.have.property("payload", data[count]); msg.should.have.property("payload");
data.should.containDeep([msg.payload]);
if (count == 1) { if (count == 1) {
// Check they got appended as expected // Check they got appended as expected
var f = fs.readFileSync(fileToTest).toString(); var f = fs.readFileSync(fileToTest).toString();
@ -233,20 +256,25 @@ describe('file Nodes', function() {
var n2 = helper.getNode("helperNode1"); var n2 = helper.getNode("helperNode1");
n2.on("input", function (msg) { n2.on("input", function (msg) {
msg.should.have.property("payload", "fine"); try {
msg.should.have.property("filename", fileToTest); msg.should.have.property("payload", "fine");
msg.should.have.property("filename", fileToTest);
var f = fs.readFileSync(fileToTest).toString(); var f = fs.readFileSync(fileToTest).toString();
if (os.type() !== "Windows_NT") { if (os.type() !== "Windows_NT") {
f.should.have.length(5); f.should.have.length(5);
f.should.equal("fine\n"); f.should.equal("fine\n");
} }
else { else {
f.should.have.length(6); f.should.have.length(6);
f.should.equal("fine\r\n"); f.should.equal("fine\r\n");
} }
done(); done();
}); }
catch (e) {
done(e);
}
});
n1.receive({payload:"fine", filename:fileToTest}); n1.receive({payload:"fine", filename:fileToTest});
}); });