test_ipc_daemon: implement internal SleepProcess
authorZac Medico <zmedico@gentoo.org>
Fri, 5 Oct 2012 04:08:01 +0000 (21:08 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 5 Oct 2012 04:08:01 +0000 (21:08 -0700)
Emulate the sleep command, in order to ensure a consistent return code
when it is killed by SIGTERM (see bug #437180).

pym/portage/tests/ebuild/test_ipc_daemon.py

index fc14671ba473d46e3bd67878ea02f11a005eafec..77277fe8ec1881896bd1574cc1e4c41dcf125cec 100644 (file)
@@ -13,11 +13,21 @@ from portage.const import BASH_BINARY
 from portage.locks import hardlock_cleanup
 from portage.package.ebuild._ipc.ExitCommand import ExitCommand
 from portage.util import ensure_dirs
+from portage.util._async.ForkProcess import ForkProcess
 from _emerge.SpawnProcess import SpawnProcess
 from _emerge.EbuildBuildDir import EbuildBuildDir
 from _emerge.EbuildIpcDaemon import EbuildIpcDaemon
 from _emerge.TaskScheduler import TaskScheduler
 
+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 = 40000 # 40 seconds
@@ -104,9 +114,8 @@ class IpcDaemonTestCase(TestCase):
                                        input_fifo=input_fifo,
                                        output_fifo=output_fifo,
                                        scheduler=task_scheduler.sched_iface)
-                               proc = SpawnProcess(
-                                       args=[BASH_BINARY, "-c", 'exec sleep %d' % sleep_time_s],
-                                       env=env, scheduler=task_scheduler.sched_iface)
+                               proc = SleepProcess(seconds=sleep_time_s,
+                                       scheduler=task_scheduler.sched_iface)
 
                                self.received_command = False
                                def exit_command_callback():