ci: Extend the MQTT weekend test to check mqtt-enqueue api

This commit is contained in:
David Cermak
2020-12-15 16:21:29 +01:00
committed by bot
parent 9185f8f42c
commit 9740db5004
2 changed files with 36 additions and 29 deletions

View File

@@ -56,7 +56,7 @@ def on_message(client, userdata, msg):
message_log += "Received data:" + msg.topic + " " + payload + "\n" message_log += "Received data:" + msg.topic + " " + payload + "\n"
def test_single_config(dut, transport, qos, repeat, published): def test_single_config(dut, transport, qos, repeat, published, queue = 0):
global expected_count global expected_count
global expected_data global expected_data
global message_log global message_log
@@ -65,7 +65,7 @@ def test_single_config(dut, transport, qos, repeat, published):
expected_count = 0 expected_count = 0
message_log = "" message_log = ""
expected_data = sample_string * repeat expected_data = sample_string * repeat
print("PUBLISH TEST: transport:{}, qos:{}, sequence:{}, sample msg:'{}'".format(transport, qos, published, expected_data)) print("PUBLISH TEST: transport:{}, qos:{}, sequence:{}, enqueue:{}, sample msg:'{}'".format(transport, qos, published, queue, expected_data))
client = None client = None
try: try:
if transport in ["ws", "wss"]: if transport in ["ws", "wss"]:
@@ -89,7 +89,7 @@ def test_single_config(dut, transport, qos, repeat, published):
if not event_client_connected.wait(timeout=30): if not event_client_connected.wait(timeout=30):
raise ValueError("ENV_TEST_FAILURE: Test script cannot connect to broker: {}".format(broker_host[transport])) raise ValueError("ENV_TEST_FAILURE: Test script cannot connect to broker: {}".format(broker_host[transport]))
client.subscribe(subscribe_topic, qos) client.subscribe(subscribe_topic, qos)
dut.write("{} {} {} {} {}".format(transport, sample_string, repeat, published, qos), eol="\n") dut.write("{} {} {} {} {} {}".format(transport, sample_string, repeat, published, qos, queue), eol="\n")
try: try:
# waiting till subscribed to defined topic # waiting till subscribed to defined topic
dut.expect(re.compile(r"MQTT_EVENT_SUBSCRIBED"), timeout=30) dut.expect(re.compile(r"MQTT_EVENT_SUBSCRIBED"), timeout=30)
@@ -105,7 +105,7 @@ def test_single_config(dut, transport, qos, repeat, published):
if expected_count == published or (expected_count > published and qos == 1): if expected_count == published or (expected_count > published and qos == 1):
print("All data received from ESP32...") print("All data received from ESP32...")
else: else:
raise ValueError("Not all data received from ESP32: Expected:{}x{}, Received:{}x{}".format(expected_data, published, message_log, expected_count)) raise ValueError("Not all data received from ESP32: Expected:{}x{}, Received:{}x{}".format(expected_count, published, expected_data, message_log))
finally: finally:
event_stop_client.set() event_stop_client.set()
thread1.join() thread1.join()
@@ -149,29 +149,30 @@ def test_weekend_mqtt_publish(env, extra_data):
raise raise
for qos in [0, 1, 2]: for qos in [0, 1, 2]:
for transport in ["tcp", "ssl", "ws", "wss"]: for transport in ["tcp", "ssl", "ws", "wss"]:
for q in [0, 1]:
if broker_host[transport] is None: if broker_host[transport] is None:
print('Skipping transport: {}...'.format(transport)) print('Skipping transport: {}...'.format(transport))
continue continue
# simple test with empty message # simple test with empty message
test_single_config(dut1, transport, qos, 0, 5) test_single_config(dut1, transport, qos, 0, 5, q)
# decide on broker what level of test will pass (local broker works the best) # decide on broker what level of test will pass (local broker works the best)
if broker_host[transport].startswith("192.168") and qos < 1: if broker_host[transport].startswith("192.168") and qos > 0 and q == 0:
# medium size, medium repeated # medium size, medium repeated
test_single_config(dut1, transport, qos, 5, 50) test_single_config(dut1, transport, qos, 5, 50, q)
# long data # long data
test_single_config(dut1, transport, qos, 1000, 10) test_single_config(dut1, transport, qos, 1000, 10, q)
# short data, many repeats # short data, many repeats
test_single_config(dut1, transport, qos, 2, 200) test_single_config(dut1, transport, qos, 2, 200, q)
elif transport in ["ws", "wss"]: elif transport in ["ws", "wss"]:
# more relaxed criteria for websockets! # more relaxed criteria for websockets!
test_single_config(dut1, transport, qos, 2, 5) test_single_config(dut1, transport, qos, 2, 5, q)
test_single_config(dut1, transport, qos, 50, 1) test_single_config(dut1, transport, qos, 50, 1, q)
test_single_config(dut1, transport, qos, 10, 20) test_single_config(dut1, transport, qos, 10, 20, q)
else: else:
# common configuration should be good for most public mosquittos # common configuration should be good for most public mosquittos
test_single_config(dut1, transport, qos, 5, 10) test_single_config(dut1, transport, qos, 5, 10, q)
test_single_config(dut1, transport, qos, 500, 3) test_single_config(dut1, transport, qos, 500, 3, q)
test_single_config(dut1, transport, qos, 1, 50) test_single_config(dut1, transport, qos, 1, 50, q)
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -126,13 +126,14 @@ void publish_test(const char* line)
char pattern[32]; char pattern[32];
char transport[32]; char transport[32];
int repeat = 0; int repeat = 0;
int enqueue = 0;
static bool is_mqtt_init = false; static bool is_mqtt_init = false;
if (!is_mqtt_init) { if (!is_mqtt_init) {
mqtt_app_start(); mqtt_app_start();
is_mqtt_init = true; is_mqtt_init = true;
} }
sscanf(line, "%s %s %d %d %d", transport, pattern, &repeat, &expected_published, &qos_test); sscanf(line, "%s %s %d %d %d %d", transport, pattern, &repeat, &expected_published, &qos_test, &enqueue);
ESP_LOGI(TAG, "PATTERN:%s REPEATED:%d PUBLISHED:%d\n", pattern, repeat, expected_published); ESP_LOGI(TAG, "PATTERN:%s REPEATED:%d PUBLISHED:%d\n", pattern, repeat, expected_published);
int pattern_size = strlen(pattern); int pattern_size = strlen(pattern);
free(expected_data); free(expected_data);
@@ -169,7 +170,12 @@ void publish_test(const char* line)
xEventGroupWaitBits(mqtt_event_group, CONNECTED_BIT, false, true, portMAX_DELAY); xEventGroupWaitBits(mqtt_event_group, CONNECTED_BIT, false, true, portMAX_DELAY);
for (int i = 0; i < expected_published; i++) { for (int i = 0; i < expected_published; i++) {
int msg_id = esp_mqtt_client_publish(mqtt_client, CONFIG_EXAMPLE_PUBLISH_TOPIC, expected_data, expected_size, qos_test, 0); int msg_id;
if (enqueue) {
msg_id = esp_mqtt_client_enqueue(mqtt_client, CONFIG_EXAMPLE_PUBLISH_TOPIC, expected_data, expected_size, qos_test, 0, true);
} else {
msg_id = esp_mqtt_client_publish(mqtt_client, CONFIG_EXAMPLE_PUBLISH_TOPIC, expected_data, expected_size, qos_test, 0);
}
ESP_LOGI(TAG, "[%d] Publishing...", msg_id); ESP_LOGI(TAG, "[%d] Publishing...", msg_id);
} }
} }