diff options
Diffstat (limited to 'pym/portage/tests/ebuild/test_ipc_daemon.py')
-rw-r--r-- | pym/portage/tests/ebuild/test_ipc_daemon.py | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/pym/portage/tests/ebuild/test_ipc_daemon.py b/pym/portage/tests/ebuild/test_ipc_daemon.py index 77277fe8e..d4328a1d6 100644 --- a/pym/portage/tests/ebuild/test_ipc_daemon.py +++ b/pym/portage/tests/ebuild/test_ipc_daemon.py @@ -1,4 +1,4 @@ -# Copyright 2010-2011 Gentoo Foundation +# Copyright 2010-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import tempfile @@ -14,10 +14,12 @@ 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 portage.util._async.TaskScheduler import TaskScheduler +from portage.util._eventloop.global_event_loop import global_event_loop +from _emerge.PollScheduler import PollScheduler from _emerge.SpawnProcess import SpawnProcess from _emerge.EbuildBuildDir import EbuildBuildDir from _emerge.EbuildIpcDaemon import EbuildIpcDaemon -from _emerge.TaskScheduler import TaskScheduler class SleepProcess(ForkProcess): """ @@ -33,6 +35,7 @@ class IpcDaemonTestCase(TestCase): _SCHEDULE_TIMEOUT = 40000 # 40 seconds def testIpcDaemon(self): + event_loop = global_event_loop() tmpdir = tempfile.mkdtemp() build_dir = None try: @@ -54,9 +57,8 @@ class IpcDaemonTestCase(TestCase): env["__PORTAGE_TEST_HARDLINK_LOCKS"] = \ os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] - task_scheduler = TaskScheduler(max_jobs=2) build_dir = EbuildBuildDir( - scheduler=task_scheduler.sched_iface, + scheduler=PollScheduler(event_loop=event_loop).sched_iface, settings=env) build_dir.lock() ensure_dirs(env['PORTAGE_BUILDDIR']) @@ -71,26 +73,23 @@ class IpcDaemonTestCase(TestCase): commands = {'exit' : exit_command} daemon = EbuildIpcDaemon(commands=commands, input_fifo=input_fifo, - output_fifo=output_fifo, - scheduler=task_scheduler.sched_iface) + output_fifo=output_fifo) proc = SpawnProcess( args=[BASH_BINARY, "-c", '"$PORTAGE_BIN_PATH"/ebuild-ipc exit %d' % exitcode], - env=env, scheduler=task_scheduler.sched_iface) + env=env) + task_scheduler = TaskScheduler(iter([daemon, proc]), + max_jobs=2, event_loop=event_loop) self.received_command = False def exit_command_callback(): self.received_command = True - task_scheduler.clear() - task_scheduler.wait() + task_scheduler.cancel() exit_command.reply_hook = exit_command_callback start_time = time.time() - task_scheduler.add(daemon) - task_scheduler.add(proc) - task_scheduler.run(timeout=self._SCHEDULE_TIMEOUT) - task_scheduler.clear() - task_scheduler.wait() + self._run(event_loop, task_scheduler, self._SCHEDULE_TIMEOUT) + hardlock_cleanup(env['PORTAGE_BUILDDIR'], remove_all_locks=True) @@ -101,7 +100,7 @@ class IpcDaemonTestCase(TestCase): self.assertEqual(daemon.isAlive(), False) self.assertEqual(exit_command.exitcode, exitcode) - # Intentionally short timeout test for QueueScheduler.run() + # Intentionally short timeout test for EventLoop/AsyncScheduler. # Use a ridiculously long sleep_time_s in case the user's # system is heavily loaded (see bug #436334). sleep_time_s = 600 #600.000 seconds @@ -116,20 +115,18 @@ class IpcDaemonTestCase(TestCase): scheduler=task_scheduler.sched_iface) proc = SleepProcess(seconds=sleep_time_s, scheduler=task_scheduler.sched_iface) + task_scheduler = TaskScheduler(iter([daemon, proc]), + max_jobs=2, event_loop=event_loop) self.received_command = False def exit_command_callback(): self.received_command = True - task_scheduler.clear() - task_scheduler.wait() + task_scheduler.cancel() exit_command.reply_hook = exit_command_callback start_time = time.time() - task_scheduler.add(daemon) - task_scheduler.add(proc) - task_scheduler.run(timeout=short_timeout_ms) - task_scheduler.clear() - task_scheduler.wait() + self._run(event_loop, task_scheduler, short_timeout_ms) + hardlock_cleanup(env['PORTAGE_BUILDDIR'], remove_all_locks=True) @@ -144,3 +141,20 @@ class IpcDaemonTestCase(TestCase): if build_dir is not None: build_dir.unlock() shutil.rmtree(tmpdir) + + def _timeout_callback(self): + self._timed_out = True + + def _run(self, event_loop, task_scheduler, timeout): + self._timed_out = False + timeout_id = event_loop.timeout_add(timeout, self._timeout_callback) + + try: + task_scheduler.start() + while not self._timed_out and task_scheduler.poll() is None: + event_loop.iteration() + if self._timed_out: + task_scheduler.cancel() + task_scheduler.wait() + finally: + event_loop.source_remove(timeout_id) |