commit: 24db094b68a2024cfd23e0366d8a81e8bded5838 Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Wed Oct 4 02:37:00 2023 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Wed Oct 4 02:39:26 2023 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=24db094b
tests: Migrate to ForkProcess target parameter Bug: https://bugs.gentoo.org/915099 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> lib/portage/tests/ebuild/test_doebuild_fd_pipes.py | 16 +++++----------- lib/portage/tests/ebuild/test_ipc_daemon.py | 16 +++------------- lib/portage/tests/util/futures/test_iter_completed.py | 7 +++---- 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py b/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py index 536e8d8648..51ddc23908 100644 --- a/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py +++ b/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py @@ -1,4 +1,4 @@ -# Copyright 2013-2016 Gentoo Foundation +# Copyright 2013-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 import portage @@ -12,13 +12,6 @@ from _emerge.Package import Package from _emerge.PipeReader import PipeReader -class DoebuildProcess(ForkProcess): - __slots__ = ("doebuild_kwargs", "doebuild_pargs") - - def _run(self): - return portage.doebuild(*self.doebuild_pargs, **self.doebuild_kwargs) - - class DoebuildFdPipesTestCase(TestCase): def testDoebuild(self): """ @@ -126,9 +119,10 @@ class DoebuildFdPipesTestCase(TestCase): ): pr, pw = os.pipe() - producer = DoebuildProcess( - doebuild_pargs=(ebuildpath, phase), - doebuild_kwargs={ + producer = ForkProcess( + target=portage.doebuild, + args=(ebuildpath, phase), + kwargs={ "settings": settings, "mydbapi": portdb, "tree": "porttree", diff --git a/lib/portage/tests/ebuild/test_ipc_daemon.py b/lib/portage/tests/ebuild/test_ipc_daemon.py index 55094f9bdd..0beb69ddfc 100644 --- a/lib/portage/tests/ebuild/test_ipc_daemon.py +++ b/lib/portage/tests/ebuild/test_ipc_daemon.py @@ -21,18 +21,6 @@ from _emerge.EbuildBuildDir import EbuildBuildDir from _emerge.EbuildIpcDaemon import EbuildIpcDaemon -class SleepProcess(ForkProcess): - """ - Emulate the sleep command, in order to ensure a consistent - return code when it is killed by SIGTERM (see bug #437180). - """ - - __slots__ = ("seconds",) - - def _run(self): - time.sleep(self.seconds) - - class IpcDaemonTestCase(TestCase): _SCHEDULE_TIMEOUT = 40 # seconds @@ -124,7 +112,9 @@ class IpcDaemonTestCase(TestCase): daemon = EbuildIpcDaemon( commands=commands, input_fifo=input_fifo, output_fifo=output_fifo ) - proc = SleepProcess(seconds=sleep_time_s) + # Emulate the sleep command, in order to ensure a consistent + # return code when it is killed by SIGTERM (see bug #437180). + proc = ForkProcess(target=time.sleep, args=(sleep_time_s,)) task_scheduler = TaskScheduler( iter([daemon, proc]), max_jobs=2, event_loop=event_loop ) diff --git a/lib/portage/tests/util/futures/test_iter_completed.py b/lib/portage/tests/util/futures/test_iter_completed.py index bda900505b..0c549018e5 100644 --- a/lib/portage/tests/util/futures/test_iter_completed.py +++ b/lib/portage/tests/util/futures/test_iter_completed.py @@ -1,8 +1,9 @@ -# Copyright 2023 Gentoo Foundation +# Copyright 2018-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 import time +import functools import pytest from portage.tests import TestCase @@ -19,6 +20,7 @@ class SleepProcess(ForkProcess): __slots__ = ("future", "seconds") def _start(self): + self.target = functools.partial(time.sleep, self.seconds) self.addExitListener(self._future_done) ForkProcess._start(self) @@ -26,9 +28,6 @@ class SleepProcess(ForkProcess): if not self.future.cancelled(): self.future.set_result(self.seconds) - def _run(self): - time.sleep(self.seconds) - class IterCompletedTestCase(TestCase): # Mark this as todo, since we don't want to fail if heavy system load causes