def setUp(self): super().setUp() self._set_up_safe_guards() # Reset singletons so that they get recreated for every test that uses them. Configuration.reset_singleton() UnhandledExceptionHandler.reset_singleton() # Explicitly initialize UnhandledExceptionHandler singleton here (on the main thread) since it sets up signal # handlers that must execute on the main thread. UnhandledExceptionHandler.singleton() MasterConfigLoader().configure_defaults(Configuration.singleton()) MasterConfigLoader().configure_postload(Configuration.singleton()) self.patch('app.util.conf.master_config_loader.MasterConfigLoader.load_from_config_file') # Configure logging to go to stdout. This makes debugging easier by allowing us to see logs for failed tests. log.configure_logging('DEBUG') # Then stub out configure_logging so we don't end up logging to real files during testing. self.patch('app.util.log.configure_logging') # Set up TestHandler. This allows asserting on log messages in tests. self.log_handler = logbook.TestHandler(bubble=True) self.log_handler.push_application() self._base_setup_called = True
def initialize_unhandled_exception_handler(): # Note: Unfortunately we can't use `self.assertRaises` here since this executes on a different thread. # todo: After exceptions in test threads are being caught, simplify this test to use self.assertRaises. UnhandledExceptionHandler.reset_singleton() try: UnhandledExceptionHandler.singleton() except Exception: nonlocal exception_raised exception_raised = True
def test_handles_platform_does_not_support_SIGINFO(self): UnhandledExceptionHandler.reset_singleton() mock_signal = self.patch('app.util.unhandled_exception_handler.signal') def register_signal_handler(sig, _): if sig == process_utils.SIGINFO: raise ValueError mock_signal.signal.side_effect = register_signal_handler UnhandledExceptionHandler.singleton()
def setUp(self): super().setUp() self.addCleanup(patch.stopall) self._patched_items = {} self._blacklist_methods_not_allowed_in_unit_tests() # Stub out a few library dependencies that launch subprocesses. self.patch( 'app.util.autoversioning.get_version').return_value = '0.0.0' self.patch('app.util.conf.base_config_loader.platform.node' ).return_value = self._fake_hostname if self._do_network_mocks: # requests.Session() also makes some subprocess calls on instantiation. self.patch('app.util.network.requests.Session') # Stub out Network.are_hosts_same() call with a simple string comparison. self.patch('app.util.network.Network.are_hosts_same', new=lambda host_a, host_b: host_a == host_b) # Reset singletons so that they get recreated for every test that uses them. Configuration.reset_singleton() UnhandledExceptionHandler.reset_singleton() SlaveRegistry.reset_singleton() # Explicitly initialize UnhandledExceptionHandler singleton here (on the main thread) since it sets up signal # handlers that must execute on the main thread. UnhandledExceptionHandler.singleton() MasterConfigLoader().configure_defaults(Configuration.singleton()) MasterConfigLoader().configure_postload(Configuration.singleton()) self.patch( 'app.util.conf.master_config_loader.MasterConfigLoader.load_from_config_file' ) # Reset counters Slave._slave_id_counter = Counter() Build._build_id_counter = Counter() analytics._event_id_generator = Counter() # Configure logging to go to stdout. This makes debugging easier by allowing us to see logs for failed tests. log.configure_logging('DEBUG') # Then stub out configure_logging so we don't end up logging to real files during testing. self.patch('app.util.log.configure_logging') # Set up TestHandler. This allows asserting on log messages in tests. self.log_handler = logbook.TestHandler(bubble=True) self.log_handler.push_application() self._base_setup_called = True
def setUp(self): super().setUp() self.addCleanup(patch.stopall) self._patched_items = {} self._blacklist_methods_not_allowed_in_unit_tests() # Stub out a few library dependencies that launch subprocesses. self.patch('app.util.autoversioning.get_version').return_value = '0.0.0' self.patch('app.util.conf.base_config_loader.platform.node').return_value = self._fake_hostname if self._do_network_mocks: # requests.Session() also makes some subprocess calls on instantiation. self.patch('app.util.network.requests.Session') # Stub out Network.are_hosts_same() call with a simple string comparison. self.patch('app.util.network.Network.are_hosts_same', new=lambda host_a, host_b: host_a == host_b) # Reset singletons so that they get recreated for every test that uses them. Configuration.reset_singleton() UnhandledExceptionHandler.reset_singleton() SlaveRegistry.reset_singleton() # Explicitly initialize UnhandledExceptionHandler singleton here (on the main thread) since it sets up signal # handlers that must execute on the main thread. UnhandledExceptionHandler.singleton() MasterConfigLoader().configure_defaults(Configuration.singleton()) MasterConfigLoader().configure_postload(Configuration.singleton()) self.patch('app.util.conf.master_config_loader.MasterConfigLoader.load_from_config_file') # Reset counters Slave._slave_id_counter = Counter() Build._build_id_counter = Counter() analytics._event_id_generator = Counter() # Configure logging to go to stdout. This makes debugging easier by allowing us to see logs for failed tests. log.configure_logging('DEBUG') # Then stub out configure_logging so we don't end up logging to real files during testing. self.patch('app.util.log.configure_logging') # Set up TestHandler. This allows asserting on log messages in tests. self.log_handler = logbook.TestHandler(bubble=True) self.log_handler.push_application() self._base_setup_called = True