From 1df301a97dd5f5ce7c5514b17a6d90b9a7ea11c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 22 Aug 2024 05:39:39 +0200 Subject: [PATCH] tests: wait for child process in vm_update tests Don't leak child processes after the test, even if they would terminate after a timeout anyway. --- qubes/tests/integ/vm_update.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/qubes/tests/integ/vm_update.py b/qubes/tests/integ/vm_update.py index e9732d9e2..093df1009 100644 --- a/qubes/tests/integ/vm_update.py +++ b/qubes/tests/integ/vm_update.py @@ -20,6 +20,7 @@ # License along with this library; if not, see . # import asyncio +import contextlib import os import shutil import subprocess @@ -226,6 +227,13 @@ def setUp(self): name=self.make_vm_name('vm1'), label='red') self.loop.run_until_complete(self.testvm1.create_on_disk()) + self.repo_proc = None + + def tearDown(self): + if self.repo_proc: + self.repo_proc.terminate() + self.loop.run_until_complete(self.repo_proc.wait()) + super().tearDown() def test_000_simple_update(self): """ @@ -322,12 +330,12 @@ def create_repo_and_serve(self): """ if self.template.count("debian") or self.template.count("whonix"): self.create_repo_apt() - self.loop.run_until_complete(self.netvm_repo.run( + self.repo_proc = self.loop.run_until_complete(self.netvm_repo.run( 'cd /tmp/apt-repo && python3 -m http.server 8080', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)) elif self.template.count("fedora"): self.create_repo_yum() - self.loop.run_until_complete(self.netvm_repo.run( + self.repo_proc = self.loop.run_until_complete(self.netvm_repo.run( 'cd /tmp/yum-repo && python3 -m http.server 8080', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)) else: @@ -482,9 +490,11 @@ def turn_off_repo(self): :type self: qubes.tests.SystemTestCase | VmUpdatesMixin """ - self.loop.run_until_complete(self.netvm_repo.run( + self.loop.run_until_complete(self.netvm_repo.run_for_stdio( r"kill -9 `ps -ef | grep python | awk '{print $2}'`", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)) + self.loop.run_until_complete(self.repo_proc.wait()) + self.repo_proc = None def update_via_proxy_qubes_vm_update_impl( self,