From e8937cbf671069f5335f2ccd9e7b36a8bac19e00 Mon Sep 17 00:00:00 2001 From: Benjamin Dweck Date: Fri, 16 Oct 2020 01:31:57 +0200 Subject: [PATCH] Automated running test brokers --- test/run-broker.bat | 2 +- test/run-broker.sh | 2 +- test/test_integration_pub_sub.py | 14 +++++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/test/run-broker.bat b/test/run-broker.bat index 93db891..c914d2a 100644 --- a/test/run-broker.bat +++ b/test/run-broker.bat @@ -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 diff --git a/test/run-broker.sh b/test/run-broker.sh index a58c5a3..34ab7af 100644 --- a/test/run-broker.sh +++ b/test/run-broker.sh @@ -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 \ No newline at end of file diff --git a/test/test_integration_pub_sub.py b/test/test_integration_pub_sub.py index ea3bf10..476925e 100644 --- a/test/test_integration_pub_sub.py +++ b/test/test_integration_pub_sub.py @@ -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)