diff --git a/tests/test_build/test_build.py b/tests/test_build/test_build.py index a7e3a3f2..df5fb56a 100644 --- a/tests/test_build/test_build.py +++ b/tests/test_build/test_build.py @@ -10,6 +10,7 @@ from os import path, mkdir from os.path import dirname import re import sched +import signal from random import randint from shutil import copyfile @@ -118,25 +119,42 @@ def main(initial_messages, stop_condition): consumers = [module_build_service.scheduler.consumer.MBSConsumer] - # The events.EventTrap context handler allows us to detect exceptions - # in event handlers and re-raise them here so that tests fail usefully - # rather than just hang. - with events.EventTrap() as trap: - # Note that the hub we kick off here cannot send any message. You - # should use fedmsg.publish(...) still for that. - moksha.hub.main( - # Pass in our config dict - options=config, - # Only run the specified consumers if any are so specified. - consumers=consumers, - # Do not run default producers. - producers=[], - # Tell moksha to quiet its logging. - framework=False, - ) + old_run = moksha.hub.reactor.reactor.run + old_sigint_handler = signal.getsignal(signal.SIGINT) - if trap.exception: - raise trap.exception + def trap_sigint(self, *args): + try: + raise KeyboardInterrupt() + except KeyboardInterrupt as e: + events.EventTrap.set_exception(e) + + def set_signals_and_run(*args, **kwargs): + signal.signal(signal.SIGINT, trap_sigint) + try: + old_run(*args, **kwargs) + finally: + signal.signal(signal.SIGINT, old_sigint_handler) + + with patch('moksha.hub.reactor.reactor.run', set_signals_and_run): + # The events.EventTrap context handler allows us to detect exceptions + # in event handlers and re-raise them here so that tests fail usefully + # rather than just hang. + with events.EventTrap() as trap: + # Note that the hub we kick off here cannot send any message. You + # should use fedmsg.publish(...) still for that. + moksha.hub.main( + # Pass in our config dict + options=config, + # Only run the specified consumers if any are so specified. + consumers=consumers, + # Do not run default producers. + producers=[], + # Tell moksha to quiet its logging. + framework=False, + ) + + if trap.exception: + raise trap.exception class FakeSCM(object):