diff options
author | Zac Medico <zmedico@gentoo.org> | 2010-08-12 22:08:56 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-08-12 22:08:56 -0700 |
commit | 15e1a041ddd6bdbc6dc30b350e16c864f8d4c334 (patch) | |
tree | b610acace1e39295f7489abf88f9c8d8cb067bd6 /pym/portage/tests/ebuild/test_ipc_daemon.py | |
parent | Split out an EbuildIpcDaemon class from FifoIpcDaemon. (diff) | |
download | portage-15e1a041ddd6bdbc6dc30b350e16c864f8d4c334.tar.gz portage-15e1a041ddd6bdbc6dc30b350e16c864f8d4c334.tar.bz2 portage-15e1a041ddd6bdbc6dc30b350e16c864f8d4c334.zip |
Make IpcDaemonTestCase demonstrate an EbuildIpcDaemon based
replacement for EBUILD_EXIT_STATUS_FILE.
Diffstat (limited to 'pym/portage/tests/ebuild/test_ipc_daemon.py')
-rw-r--r-- | pym/portage/tests/ebuild/test_ipc_daemon.py | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/pym/portage/tests/ebuild/test_ipc_daemon.py b/pym/portage/tests/ebuild/test_ipc_daemon.py index 488bd3999..bd27a38d1 100644 --- a/pym/portage/tests/ebuild/test_ipc_daemon.py +++ b/pym/portage/tests/ebuild/test_ipc_daemon.py @@ -12,6 +12,28 @@ from _emerge.SpawnProcess import SpawnProcess from _emerge.EbuildIpcDaemon import EbuildIpcDaemon from _emerge.TaskScheduler import TaskScheduler +class ExitCommand(object): + + def __init__(self): + self.callback = None + self.exitcode = None + + def __call__(self, argv, send_reply): + duplicate = False + if self.exitcode is not None: + # Ignore all but the first call, since if die is called + # then we certainly want to honor that exitcode, even + # the ebuild process manages to send a second exit + # command. + duplicate = True + else: + self.exitcode = int(argv[1]) + + # (stdout, stderr, returncode) + send_reply(('', '', 0)) + if not duplicate and self.callback is not None: + self.callback() + class IpcDaemonTestCase(TestCase): def testIpcDaemon(self): @@ -25,16 +47,25 @@ class IpcDaemonTestCase(TestCase): output_fifo = os.path.join(tmpdir, '.ipc_out') os.mkfifo(input_fifo) os.mkfifo(output_fifo) - task_scheduler = TaskScheduler(max_jobs=2) - daemon = EbuildIpcDaemon(input_fifo=input_fifo, - output_fifo=output_fifo, - scheduler=task_scheduler.sched_iface) - proc = SpawnProcess( - args=[BASH_BINARY, "-c", '"$PORTAGE_BIN_PATH"/ebuild-ipc exit 0'], - env=env, scheduler=task_scheduler.sched_iface) - task_scheduler.add(daemon) - task_scheduler.add(proc) - task_scheduler.run() - self.assertEqual(proc.returncode, os.EX_OK) + for exitcode in (0, 1, 2): + task_scheduler = TaskScheduler(max_jobs=2) + exit_command = ExitCommand() + commands = {'exit' : exit_command} + daemon = EbuildIpcDaemon(commands=commands, + input_fifo=input_fifo, + output_fifo=output_fifo, + scheduler=task_scheduler.sched_iface) + proc = SpawnProcess( + args=[BASH_BINARY, "-c", + '"$PORTAGE_BIN_PATH"/ebuild-ipc exit %d' % exitcode], + env=env, scheduler=task_scheduler.sched_iface) + def exit_command_callback(): + daemon.cancel() + proc.cancel() + exit_command.callback = exit_command_callback + task_scheduler.add(daemon) + task_scheduler.add(proc) + task_scheduler.run() + self.assertEqual(exit_command.exitcode, exitcode) finally: shutil.rmtree(tmpdir) |