Skip to content

Commit

Permalink
Test multiple concurrent connections with different authentications
Browse files Browse the repository at this point in the history
  • Loading branch information
domschl committed Aug 18, 2023
1 parent f7b5234 commit 90937b4
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 10 deletions.
11 changes: 11 additions & 0 deletions selftest/fhem-config-addon.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@ define allowWebPwd allowed
# test:secretsauce NOTE: do not reuse those values for actual installations!
attr allowWebPwd basicAuth dGVzdDpzZWNyZXRzYXVjZQ==
attr allowWebPwd validFor WebPwd

define MultiWebPwd FHEMWEB 8087 global
attr MultiWebPwd HTTPS 1
attr MultiWebPwd sslVersion TLSv12:!SSLv3
attr MultiWebPwd longpoll 1
define allowMultiWebPwd allowed
# echo -n "toast:salad" | base64
# dG9hc3Q6c2FsYWQ=
attr allowMultiWebPwd basicAuth dG9hc3Q6c2FsYWQ=
attr allowMultiWebPwd validFor WebPwd

#################################################################################
90 changes: 80 additions & 10 deletions selftest/selftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,26 +274,32 @@ def create_device(fhi, name, readings):
"username": "test",
"password": "secretsauce",
},
{
"protocol": "https",
"port": 8087,
"username": "toast",
"password": "salad",
},
]

first = True
devs = [
{
"name": "clima_sensor1",
"readings": {"temperature": 18.2, "humidity": 88.2},
},
{
"name": "clima_sensor2",
"readings": {"temperature": 19.1, "humidity": 85.7},
},
]
log.info("")
log.info("----------------- Fhem ------------")
log.info("Testing python-fhem Fhem():")
for connection in connections:
log.info("Testing connection to {} via {}".format(config["testhost"], connection))
fh = fhem.Fhem(config["testhost"], **connection)

devs = [
{
"name": "clima_sensor1",
"readings": {"temperature": 18.2, "humidity": 88.2},
},
{
"name": "clima_sensor2",
"readings": {"temperature": 19.1, "humidity": 85.7},
},
]

if first is True:
for dev in devs:
Expand Down Expand Up @@ -355,6 +361,70 @@ def create_device(fhi, name, readings):
log.info("states received: {}, ok.".format(len(states)))
fh.close()

log.info("---------------MultiConnect--------------------")
fhm = []
for connection in connections[-2:]:
log.info("Testing multi-connection to {} via {}".format(config["testhost"], connection))
fhm.append(fhem.Fhem(config["testhost"], **connection))

for dev in devs:
for i in range(10):
for fh in fhm:
log.debug("Repetion: {}, connection: {}".format(i + 1, fh.connection))
if fh.connected() is False:
log.info("Connecting...")
fh.connect()
for rd in dev["readings"]:
dict_value = fh.get_device_reading(dev["name"], rd, blocking=False)
try:
value = dict_value["Value"]
except:
log.error(
"Bad reply reading {} {} -> {}".format(
dev["name"], rd, dict_value
)
)
sys.exit(-7)

if value == dev["readings"][rd]:
log.debug(
"Reading-test {},{}={} ok.".format(
dev["name"], rd, dev["readings"][rd]
)
)
else:
log.error(
"Failed to set and read reading! {},{} {} != {}".format(
dev["name"], rd, value, dev["readings"][rd]
)
)
sys.exit(-5)

num_temps = 0
for dev in devs:
if "temperature" in dev["readings"]:
num_temps += 1
for fh in fhm:
temps = fh.get_readings("temperature", timeout=0.1, blocking=False)
if len(temps) != num_temps:
log.error(
"There should have been {} devices with temperature reading, but we got {}. Ans: {}".format(
num_temps, len(temps), temps
)
)
sys.exit(-6)
else:
log.info("Multiread of all devices with 'temperature' reading: ok.")

for fh in fhm:
states = fh.get_states()
if len(states) < 5:
log.error("Iconsistent number of states: {}".format(len(states)))
sys.exit(-7)
else:
log.info("states received: {}, ok.".format(len(states)))
fh.close()

log.info("---------------Queues--------------------------")
log.info("Testing python-fhem telnet FhemEventQueues():")
for connection in connections:
Expand Down

0 comments on commit 90937b4

Please sign in to comment.