mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
opportunistic tidy up MQTT tests
This commit is contained in:
parent
5a36e8fb11
commit
5c6b8e9e50
@ -219,7 +219,7 @@ describe('MQTT Nodes', function () {
|
|||||||
topic: nextTopic(),
|
topic: nextTopic(),
|
||||||
payload: '{prop:"value3", "num":3}', // send invalid JSON ...
|
payload: '{prop:"value3", "num":3}', // send invalid JSON ...
|
||||||
}
|
}
|
||||||
const hooks = { done: done, beforeLoad: null, afterLoad: null, afterConnect: null }
|
const hooks = { done: null, beforeLoad: null, afterLoad: null, afterConnect: null }
|
||||||
hooks.afterLoad = (helperNode, mqttBroker, mqttIn, mqttOut) => {
|
hooks.afterLoad = (helperNode, mqttBroker, mqttIn, mqttOut) => {
|
||||||
helperNode.on("input", function (msg) {
|
helperNode.on("input", function (msg) {
|
||||||
try {
|
try {
|
||||||
@ -345,7 +345,7 @@ describe('MQTT Nodes', function () {
|
|||||||
topic: nextTopic(),
|
topic: nextTopic(),
|
||||||
payload: '{prop:"value3", "num":3}', contentType: "application/json", // send invalid JSON ...
|
payload: '{prop:"value3", "num":3}', contentType: "application/json", // send invalid JSON ...
|
||||||
}
|
}
|
||||||
const hooks = { done: done, beforeLoad: null, afterLoad: null, afterConnect: null }
|
const hooks = { done: null, beforeLoad: null, afterLoad: null, afterConnect: null }
|
||||||
hooks.afterLoad = (helperNode, mqttBroker, mqttIn, mqttOut) => {
|
hooks.afterLoad = (helperNode, mqttBroker, mqttIn, mqttOut) => {
|
||||||
helperNode.on("input", function (msg) {
|
helperNode.on("input", function (msg) {
|
||||||
try {
|
try {
|
||||||
@ -431,7 +431,7 @@ describe('MQTT Nodes', function () {
|
|||||||
if (skipTests) { return this.skip() }
|
if (skipTests) { return this.skip() }
|
||||||
this.timeout = 2000;
|
this.timeout = 2000;
|
||||||
const options = {}
|
const options = {}
|
||||||
const hooks = { done: done, beforeLoad: null, afterLoad: null, afterConnect: null }
|
const hooks = { beforeLoad: null, afterLoad: null, afterConnect: null }
|
||||||
hooks.beforeLoad = (flow) => { //add a status node pointed at MQTT Out node (to watch for connection status change)
|
hooks.beforeLoad = (flow) => { //add a status node pointed at MQTT Out node (to watch for connection status change)
|
||||||
flow.push({ "id": "status.node", "type": "status", "name": "status_node", "scope": ["mqtt.out"], "wires": [["helper.node"]] });//add status node to watch mqtt_out
|
flow.push({ "id": "status.node", "type": "status", "name": "status_node", "scope": ["mqtt.out"], "wires": [["helper.node"]] });//add status node to watch mqtt_out
|
||||||
}
|
}
|
||||||
@ -462,18 +462,31 @@ describe('MQTT Nodes', function () {
|
|||||||
this.timeout = 2000;
|
this.timeout = 2000;
|
||||||
const baseTopic = nextTopic();
|
const baseTopic = nextTopic();
|
||||||
const brokerOptions = {
|
const brokerOptions = {
|
||||||
|
autoConnect: false,
|
||||||
protocolVersion: 4,
|
protocolVersion: 4,
|
||||||
birthTopic: baseTopic + "/birth",
|
birthTopic: baseTopic + "/birth",
|
||||||
birthPayload: "broker connected",
|
birthPayload: "broker birth",
|
||||||
birthQos: 2,
|
birthQos: 2,
|
||||||
}
|
}
|
||||||
const options = {};
|
const expectMsg = {
|
||||||
const hooks = { done: done, beforeLoad: null, afterLoad: null, afterConnect: null };
|
|
||||||
options.expectMsg = {
|
|
||||||
topic: brokerOptions.birthTopic,
|
topic: brokerOptions.birthTopic,
|
||||||
payload: brokerOptions.birthPayload,
|
payload: brokerOptions.birthPayload,
|
||||||
qos: brokerOptions.birthQos
|
qos: brokerOptions.birthQos
|
||||||
};
|
};
|
||||||
|
const options = { };
|
||||||
|
const hooks = { };
|
||||||
|
hooks.afterLoad = (helperNode, mqttBroker, mqttIn, mqttOut) => {
|
||||||
|
helperNode.on("input", function (msg) {
|
||||||
|
try {
|
||||||
|
compareMsgToExpected(msg, expectMsg);
|
||||||
|
done();
|
||||||
|
} catch (error) {
|
||||||
|
done(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
mqttIn.receive({ "action": "connect" }); //now request connect action
|
||||||
|
return true; //handled
|
||||||
|
}
|
||||||
testSendRecv(brokerOptions, { topic: brokerOptions.birthTopic }, {}, options, hooks);
|
testSendRecv(brokerOptions, { topic: brokerOptions.birthTopic }, {}, options, hooks);
|
||||||
});
|
});
|
||||||
itConditional('should publish close message', function (done) {
|
itConditional('should publish close message', function (done) {
|
||||||
@ -807,8 +820,8 @@ function waitBrokerConnect(broker, timeLimit) {
|
|||||||
let waitConnected = (broker, timeLimit) => {
|
let waitConnected = (broker, timeLimit) => {
|
||||||
const brokers = Array.isArray(broker) ? broker : [broker];
|
const brokers = Array.isArray(broker) ? broker : [broker];
|
||||||
timeLimit = timeLimit || 1000;
|
timeLimit = timeLimit || 1000;
|
||||||
let timer, resolved = false;
|
|
||||||
return new Promise( (resolve, reject) => {
|
return new Promise( (resolve, reject) => {
|
||||||
|
let timer, resolved = false;
|
||||||
timer = wait();
|
timer = wait();
|
||||||
function wait() {
|
function wait() {
|
||||||
if (brokers.every(e => e.connected == true)) {
|
if (brokers.every(e => e.connected == true)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user