summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-04-06 19:53:30 +0300
committerDevaev Maxim <[email protected]>2019-04-06 21:59:15 +0300
commitb8e3ceef6d2b7becb4b7bc8b39c9f852a465c90d (patch)
tree8ccd960d56995eaf97d0c213f52d43527f82cbf9 /tests
parent1d75b738a08c98a5d3d8ac3c685e77360f4c1267 (diff)
better cleanup testing, remove all unix sockets
Diffstat (limited to 'tests')
-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()