mirror of
https://github.com/emqx/neuron.git
synced 2026-10-17 04:40:42 +08:00
Merge pull request #1728 from eeff/eeff/dev
test(mqtt): make ft more stable
This commit is contained in:
@@ -384,7 +384,7 @@ class TestMQTT:
|
||||
conf = request.getfixturevalue(conf)
|
||||
api.node_setting_check(NODE, conf)
|
||||
api.node_ctl(NODE, config.NEU_CTL_START)
|
||||
assert 1 == mocker.connected_clients()
|
||||
mocker.assert_client_connected()
|
||||
|
||||
@description(
|
||||
given="MQTT node and conf_emqx_ssl",
|
||||
@@ -408,9 +408,9 @@ class TestMQTT:
|
||||
def test_mqtt_start_stop(self, request, mocker, conf_base):
|
||||
api.node_setting_check(NODE, conf_base)
|
||||
api.node_ctl_check(NODE, config.NEU_CTL_STOP)
|
||||
assert 0 == mocker.connected_clients()
|
||||
mocker.assert_client_disconnected()
|
||||
api.node_ctl_check(NODE, config.NEU_CTL_START)
|
||||
assert 1 == mocker.connected_clients()
|
||||
mocker.assert_client_connected()
|
||||
|
||||
@description(
|
||||
given="MQTT node and {conf}",
|
||||
@@ -498,7 +498,7 @@ class TestMQTT:
|
||||
def test_mqtt_cache(self, mocker, conf_cache):
|
||||
api.node_setting_check(NODE, conf_cache)
|
||||
api.node_ctl(NODE, config.NEU_CTL_START)
|
||||
assert 1 == mocker.connected_clients()
|
||||
mocker.assert_client_connected()
|
||||
|
||||
mocker.offline(seconds=1.5)
|
||||
ts = (time.time_ns() // 1_000_000) - INTERVAL
|
||||
@@ -521,7 +521,7 @@ class TestMQTT:
|
||||
def test_mqtt_read_bad_req(self, mocker, conf_base):
|
||||
api.node_setting_check(NODE, conf_base)
|
||||
api.node_ctl(NODE, config.NEU_CTL_START)
|
||||
assert 1 == mocker.connected_clients()
|
||||
mocker.assert_client_connected()
|
||||
|
||||
req = {
|
||||
"uuid": "bca54fe7-a2b1-43e2-a4b4-1da715d28eab",
|
||||
@@ -578,7 +578,7 @@ class TestMQTT:
|
||||
def test_mqtt_write_bad_req(self, mocker, conf_base, req):
|
||||
api.node_setting_check(NODE, conf_base)
|
||||
api.node_ctl(NODE, config.NEU_CTL_START)
|
||||
assert 1 == mocker.connected_clients()
|
||||
mocker.assert_client_connected()
|
||||
|
||||
req = {
|
||||
"uuid": "cd32be1b-c8b1-3257-94af-77f847b1ed3e",
|
||||
|
||||
@@ -60,11 +60,23 @@ class Mock:
|
||||
self.broker.start()
|
||||
self.client.connect("127.0.0.1")
|
||||
|
||||
def connected_clients(self):
|
||||
def assert_client_disconnected(self):
|
||||
"""Return number of connected clients to the broker."""
|
||||
topic = "$SYS/broker/clients/connected"
|
||||
messages = self.get(topic, num=2, timeout=2)
|
||||
return int(messages[-1]) - 1
|
||||
n = int(messages[-1]) - 1 # exclude out client
|
||||
assert n == 0, "there are connected mqtt clients"
|
||||
|
||||
def assert_client_connected(self):
|
||||
"""Return number of connected clients to the broker."""
|
||||
topic = "$SYS/broker/clients/connected"
|
||||
n = 0
|
||||
for _ in range(8):
|
||||
messages = self.get(topic, num=2, timeout=1.25)
|
||||
n = int(messages[-1]) - 1 # exclude out client
|
||||
if n != 0:
|
||||
break
|
||||
assert n > 0, "there are no connected mqtt clients"
|
||||
|
||||
def get(self, topic, num=1, timeout=1):
|
||||
"""Get message from the specified topic."""
|
||||
|
||||
Reference in New Issue
Block a user