diff options
author | Zac Medico <zmedico@gentoo.org> | 2010-09-03 15:39:15 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-09-03 15:39:15 -0700 |
commit | 1959bfc2a30aa6160dfa0b454f3af0a545bf40f0 (patch) | |
tree | de83835feb79c76da08f2eac638a68f1d1a0dede | |
parent | 35f639f21f285897903d9805569af26c3333300a (diff) | |
download | portage-1959bfc2a30aa6160dfa0b454f3af0a545bf40f0.tar.gz portage-1959bfc2a30aa6160dfa0b454f3af0a545bf40f0.tar.bz2 portage-1959bfc2a30aa6160dfa0b454f3af0a545bf40f0.zip |
Add a test case for intentionally short timeout with QueueScheduler.run().
-rw-r--r-- | pym/portage/tests/ebuild/test_ipc_daemon.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/pym/portage/tests/ebuild/test_ipc_daemon.py b/pym/portage/tests/ebuild/test_ipc_daemon.py index dee61a2d2..3298040a8 100644 --- a/pym/portage/tests/ebuild/test_ipc_daemon.py +++ b/pym/portage/tests/ebuild/test_ipc_daemon.py @@ -41,8 +41,8 @@ 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) for exitcode in (0, 1, 2): - task_scheduler = TaskScheduler(max_jobs=2) exit_command = ExitCommand() commands = {'exit' : exit_command} daemon = EbuildIpcDaemon(commands=commands, @@ -71,5 +71,39 @@ class IpcDaemonTestCase(TestCase): "command not received after %d seconds" % \ (time.time() - start_time,)) self.assertEqual(exit_command.exitcode, exitcode) + + # Intentionally short timeout test for QueueScheduler.run() + sleep_time_s = 10 # 10.000 seconds + short_timeout_ms = 10 # 0.010 seconds + + for i in range(3): + 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", 'exec sleep %d' % sleep_time_s], + env=env, scheduler=task_scheduler.sched_iface) + + self.received_command = False + def exit_command_callback(): + self.received_command = True + proc.cancel() + daemon.cancel() + + exit_command.reply_hook = exit_command_callback + task_scheduler.add(daemon) + task_scheduler.add(proc) + start_time = time.time() + task_scheduler.run(timeout=short_timeout_ms) + task_scheduler.clear() + + self.assertEqual(self.received_command, False, + "command received after %d seconds" % \ + (time.time() - start_time,)) + self.assertEqual(proc.returncode == os.EX_OK, False) + finally: shutil.rmtree(tmpdir) |