From b060861657345c74e73f6e6d332b5aa6cfc35c35 Mon Sep 17 00:00:00 2001 From: Thomas Nordquist Date: Thu, 20 Jun 2019 12:44:02 +0200 Subject: [PATCH] Increase test resiliance --- src/spec/mock-mqtt.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/spec/mock-mqtt.ts b/src/spec/mock-mqtt.ts index 83ef898..ae711d9 100644 --- a/src/spec/mock-mqtt.ts +++ b/src/spec/mock-mqtt.ts @@ -72,14 +72,16 @@ function generateData(client: mqtt.MqttClient) { client.subscribe('kitchen/lamp/set') client.on('message', (topic, payload) => { if (topic === 'kitchen/lamp/set') { - setTimeout( - () => + setTimeout(() => { + try { client.publish('kitchen/lamp/state', JSON.parse(payload.toString()).state, { retain: true, qos: 0, - }), - 500 - ) + }) + } catch (error) { + console.error(error) + } + }, 500) } })