Example #1
0
    def test_log_thread_state(self):
        msgs = []

        def logger(msg):
            msgs.append(msg)

        thread_id = current_thread_id()
        stack_utils.log_thread_state(logger, "test-thread", thread_id,
                                     "is tested")
        self.assertTrue(msgs)
Example #2
0
    def run_message_loop(self):
        threads = self._threads()
        wedged_threads = set()

        # Loop through all the threads waiting for them to finish.
        some_thread_is_alive = True
        while some_thread_is_alive:
            some_thread_is_alive = False
            t = time.time()
            for thread in threads:
                if thread.isAlive():
                    if thread in wedged_threads:
                        continue

                    some_thread_is_alive = True
                    next_timeout = thread.next_timeout()
                    if next_timeout and t > next_timeout:
                        stack_utils.log_thread_state(_log.error, thread.getName(), thread.id(), "is wedged")
                        thread.clear_next_timeout()
                        wedged_threads.add(thread)

                exception_info = thread.exception_info()
                if exception_info is not None:
                    # Re-raise the thread's exception here to make it
                    # clear that testing was aborted. Otherwise,
                    # the tests that did not run would be assumed
                    # to have passed.
                    raise exception_info[0], exception_info[1], exception_info[2]

            self._test_runner.update()

            if some_thread_is_alive:
                time.sleep(0.01)

        if wedged_threads:
            _log.warning("All remaining threads are wedged, bailing out.")
 def log_wedged_worker(self, test_name):
     stack_utils.log_thread_state(_log.error, self._client.name(), self.ident, " is wedged on test %s" % test_name)