summaryrefslogtreecommitdiff
path: root/tests/test_app_cleanup.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_app_cleanup.py')
-rw-r--r--tests/test_app_cleanup.py45
1 files changed, 42 insertions, 3 deletions
diff --git a/tests/test_app_cleanup.py b/tests/test_app_cleanup.py
index 8d9db421..d95d77de 100644
--- a/tests/test_app_cleanup.py
+++ b/tests/test_app_cleanup.py
@@ -20,15 +20,54 @@
# ========================================================================== #
+import os
+import string
+import random
+import multiprocessing
+import multiprocessing.queues
+import time
+
+import setproctitle
+
from kvmd.apps.cleanup import main
# =====
-def test_main() -> None:
- open("/tmp/foobar.sock", "w").close()
+def test_main(tmpdir) -> None: # type: ignore
+ queue: multiprocessing.queues.Queue = multiprocessing.Queue()
+
+ ustreamer_fake_name = "ustr-" + "".join(
+ random.choice(string.ascii_lowercase + string.digits)
+ for _ in range(5)
+ )
+
+ ustreamer_sock_path = os.path.abspath(str(tmpdir.join("ustreamer-fake.sock")))
+ kvmd_sock_path = os.path.abspath(str(tmpdir.join("kvmd-fake.sock")))
+
+ def ustreamer_fake() -> None:
+ setproctitle.setproctitle(ustreamer_fake_name)
+ queue.put(True)
+ while True:
+ time.sleep(1)
+
+ proc = multiprocessing.Process(target=ustreamer_fake, daemon=True)
+ proc.start()
+ assert queue.get(timeout=5)
+
+ assert proc.is_alive()
main([
"kvmd-cleanup",
"--set-options",
+ "kvmd/server/port=0",
+ "kvmd/server/unix=" + kvmd_sock_path,
"kvmd/hid/device=/dev/null",
- "kvmd/streamer/unix=/tmp/foobar.sock",
+ "kvmd/streamer/port=0",
+ "kvmd/streamer/unix=" + ustreamer_sock_path,
+ "kvmd/streamer/cmd=[\"%s\"]" % (ustreamer_fake_name),
])
+ assert not proc.is_alive()
+
+ assert not os.path.exists(ustreamer_sock_path)
+ assert not os.path.exists(kvmd_sock_path)
+
+ proc.join()