Automated running test brokers

This commit is contained in:
B.J. Dweck 2020-10-16 01:31:57 +02:00
parent 72be3ce411
commit e8937cbf67
3 changed files with 13 additions and 5 deletions

View File

@ -1 +1 @@
docker run -it --rm --name mosquitto -p 8883:8883 -v %cd%\broker-config:/mosquitto/config eclipse-mosquitto
docker run --rm --name mosquitto -p 8883:8883 -v %cd%\test\broker-config:/mosquitto/config eclipse-mosquitto

View File

@ -3,6 +3,6 @@
docker run -it --rm \
--user "$UID" \
-p 8883:8883 \
-v "$(pwd)/broker-config:/mosquitto/config" \
-v "$(pwd)/test/broker-config:/mosquitto/config" \
--name mosquitto \
eclipse-mosquitto

View File

@ -1,6 +1,7 @@
import json
import os
import ssl
import sys
import threading
import time
import unittest
@ -12,6 +13,7 @@ from torch_sub import torch_sub
broker_hostname = "mqtt.example.com"
broker_port = 8883
agent_config_path = "test/agent-config/"
mqtt_ca_file = agent_config_path + "ca.crt"
mqtt_cert_file = agent_config_path + "vagrant.crt"
@ -35,7 +37,6 @@ def agent_connect():
def agent_publish(client_id, onion_hostname):
payload = {
'clientId': client_id,
'timestamp': datetime.now().strftime("%d-%b-%Y (%H:%M:%S.%f)"),
@ -43,20 +44,27 @@ def agent_publish(client_id, onion_hostname):
'sshPort': 22
}
time.sleep(0.2)
time.sleep(1)
client = agent_connect()
client.publish("torch/" + client_id + "/wake", json.dumps(payload))
client.disconnect()
time.sleep(0.2)
time.sleep(1)
class GivenBrokerAndTorchAgent(unittest.TestCase):
def setUp(self) -> None:
cli = "test/run-broker.sh"
if sys.platform.startswith('win32'):
cli = "test\\run-broker.bat"
threading.Thread(target=os.system, args=(cli,), daemon=True).start()
time.sleep(2)
if os.path.exists(torch_sub.database_file):
os.remove(torch_sub.database_file)
def tearDown(self) -> None:
os.system("docker container stop mosquitto")
if os.path.exists(torch_sub.database_file):
os.remove(torch_sub.database_file)