improve start stop test
This commit is contained in:
parent
3de058ba77
commit
3bf77ec3cb
2 changed files with 22 additions and 34 deletions
|
|
@ -125,6 +125,7 @@ async def start():
|
|||
# Start web servers
|
||||
await web_server.start()
|
||||
|
||||
bumperlog.info("Starting Bumper successful")
|
||||
# Start maintenance
|
||||
while not shutting_down:
|
||||
asyncio.create_task(maintenance())
|
||||
|
|
@ -140,15 +141,12 @@ async def shutdown():
|
|||
try:
|
||||
bumperlog.info("Shutting down")
|
||||
|
||||
await mqtt_helperbot.disconnect()
|
||||
await web_server.shutdown()
|
||||
while mqtt_server.state == "starting":
|
||||
await asyncio.sleep(0.1)
|
||||
if mqtt_server.state == "started":
|
||||
await mqtt_server.shutdown()
|
||||
elif mqtt_server.state == "starting":
|
||||
while mqtt_server.state == "starting":
|
||||
await asyncio.sleep(0.1)
|
||||
if mqtt_server.state == "started":
|
||||
await mqtt_server.shutdown()
|
||||
await mqtt_helperbot.disconnect()
|
||||
if xmpp_server.server:
|
||||
if xmpp_server.server._serving:
|
||||
xmpp_server.server.close()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import asyncio
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from testfixtures import LogCapture
|
||||
|
||||
import bumper
|
||||
|
|
@ -8,46 +9,35 @@ from bumper import strtobool
|
|||
|
||||
|
||||
def test_strtobool():
|
||||
assert strtobool("t") == True
|
||||
assert strtobool("f") == False
|
||||
assert strtobool(0) == False
|
||||
assert strtobool("t") is True
|
||||
assert strtobool("f") is False
|
||||
assert strtobool(0) is False
|
||||
|
||||
|
||||
async def test_start_stop():
|
||||
@pytest.mark.parametrize("debug", [False, True])
|
||||
async def test_start_stop(debug: bool):
|
||||
with LogCapture() as l:
|
||||
if os.path.exists("tests/tmp.db"):
|
||||
os.remove("tests/tmp.db") # Remove existing db
|
||||
|
||||
if debug:
|
||||
bumper.bumper_debug = True
|
||||
|
||||
asyncio.create_task(bumper.start())
|
||||
await asyncio.sleep(0.1)
|
||||
l.check_present(("bumper", "INFO", "Starting Bumper"))
|
||||
while True:
|
||||
try:
|
||||
l.check_present(("bumper", "INFO", "Starting Bumper successful"))
|
||||
break
|
||||
except AssertionError:
|
||||
pass
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
l.clear()
|
||||
|
||||
await bumper.shutdown()
|
||||
l.check_present(
|
||||
("bumper", "INFO", "Shutting down"), ("bumper", "INFO", "Shutdown complete")
|
||||
)
|
||||
assert bumper.shutting_down == True
|
||||
|
||||
|
||||
async def test_start_stop_debug():
|
||||
with LogCapture() as l:
|
||||
if os.path.exists("tests/tmp.db"):
|
||||
os.remove("tests/tmp.db") # Remove existing db
|
||||
|
||||
bumper.bumper_listen = "0.0.0.0"
|
||||
bumper.bumper_debug = True
|
||||
asyncio.create_task(bumper.start())
|
||||
|
||||
await asyncio.sleep(0.1)
|
||||
while bumper.mqtt_server.state == "starting":
|
||||
await asyncio.sleep(0.1)
|
||||
l.check_present(("bumper", "INFO", "Starting Bumper"))
|
||||
l.clear()
|
||||
|
||||
asyncio.create_task(bumper.shutdown())
|
||||
await asyncio.sleep(0.1)
|
||||
l.check_present(
|
||||
("bumper", "INFO", "Shutting down"), ("bumper", "INFO", "Shutdown complete")
|
||||
)
|
||||
assert bumper.shutting_down == True
|
||||
assert bumper.shutting_down is True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue