Skip to content

Commit

Permalink
tests: wait for child process in vm_update tests
Browse files Browse the repository at this point in the history
Don't leak child processes after the test, even if they would terminate
after a timeout anyway.
  • Loading branch information
marmarek committed Aug 23, 2024
1 parent c793ffc commit a10a0b5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions qubes/tests/integ/vm_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# License along with this library; if not, see <https://www.gnu.org/licenses/>.
#
import asyncio
import contextlib
import os
import shutil
import subprocess
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -482,9 +490,11 @@ def turn_off_repo(self):
:type self: qubes.tests.SystemTestCase | VmUpdatesMixin
"""
self.loop.run_until_complete(self.netvm_repo.run(
r"kill -9 `ps -ef | grep python | awk '{print $2}'`",
self.loop.run_until_complete(self.netvm_repo.run_for_stdio(
r"kill -9 `ps -ef | grep [h]ttp.server | 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,
Expand Down

0 comments on commit a10a0b5

Please sign in to comment.