|
8 | 8 | from twisted.internet import threads |
9 | 9 |
|
10 | 10 | from test.settings.mqttkit import settings, influx_sensors, PROCESS_DELAY_MQTT, device_influx_sensors |
11 | | -from test.util import mqtt_json_sensor, sleep, mqtt_sensor |
| 11 | +from test.util import mqtt_json_sensor, sleep, mqtt_sensor, mqtt_ndjson_sensor |
12 | 12 |
|
13 | 13 | logger = logging.getLogger(__name__) |
14 | 14 |
|
@@ -110,6 +110,42 @@ def test_mqtt_to_influxdb_json_compact_bulk(machinery, create_influxdb, reset_in |
110 | 110 | assert record == {u'time': '2021-01-19T18:56:08Z', u'temperature': 42.84, u'humidity': 83.1} |
111 | 111 |
|
112 | 112 |
|
| 113 | +@pytest_twisted.inlineCallbacks |
| 114 | +@pytest.mark.mqtt |
| 115 | +def test_mqtt_to_influxdb_ndjson_bulk(machinery, create_influxdb, reset_influxdb): |
| 116 | + """ |
| 117 | + Publish multiple readings in NDJSON format to MQTT broker |
| 118 | + and proof they are stored in the InfluxDB database. |
| 119 | +
|
| 120 | + TODO: Grafana provisioning failed! |
| 121 | + """ |
| 122 | + |
| 123 | + # Submit multiple measurements, without timestamp. |
| 124 | + data = [ |
| 125 | + { |
| 126 | + 'temperature': 21.42, |
| 127 | + 'humidity': 41.55, |
| 128 | + }, |
| 129 | + { |
| 130 | + 'temperature': 42.84, |
| 131 | + 'humidity': 83.1, |
| 132 | + }, |
| 133 | + ] |
| 134 | + yield threads.deferToThread(mqtt_ndjson_sensor, settings.mqtt_topic_ndjson, data) |
| 135 | + |
| 136 | + # Wait for some time to process the message. |
| 137 | + yield sleep(PROCESS_DELAY_MQTT) |
| 138 | + |
| 139 | + # Proof that data arrived in InfluxDB. |
| 140 | + record = influx_sensors.get_record(index=0) |
| 141 | + del record['time'] |
| 142 | + assert record == {u'temperature': 21.42, u'humidity': 41.55} |
| 143 | + |
| 144 | + record = influx_sensors.get_record(index=1) |
| 145 | + del record['time'] |
| 146 | + assert record == {u'temperature': 42.84, u'humidity': 83.1} |
| 147 | + |
| 148 | + |
113 | 149 | @pytest_twisted.inlineCallbacks |
114 | 150 | @pytest.mark.mqtt |
115 | 151 | @pytest.mark.legacy |
|
0 commit comments