Exemple #1
0
    def test_thread_generator_tb(self):
        class FakeModel(object):
            def __init__(self, thread_id, tb):
                self.traceback = tb

        with mock.patch('openstack.common.report.models'
                        '.threading.ThreadModel', FakeModel):
            model = os_tgen.ThreadReportGenerator("fake traceback")()
            curr_thread = model.get(threading.current_thread().ident, None)
            self.assertIsNotNone(curr_thread, None)
            self.assertEqual("fake traceback", curr_thread.traceback)
    def test_thread_generator(self):
        model = os_tgen.ThreadReportGenerator()()
        # self.assertGreaterEqual(len(model.keys()), 1)
        self.assertTrue(len(model.keys()) >= 1)
        self.assertIsInstance(model[0], os_tmod.ThreadModel)
        self.assertIsNotNone(model[0].stack_trace)

        was_ok = False
        for tm in model.values():
            if tm.thread_id == threading.current_thread().ident:
                was_ok = True
                break
        self.assertTrue(was_ok)

        model.set_current_view_type('text')
        self.assertIsNotNone(str(model))
    def _readd_sections(self):
        del self.sections[self.start_section_index:]

        self.add_section('Package',
                         pgen.PackageReportGenerator(self.version_obj))

        self.add_section('Threads', tgen.ThreadReportGenerator(self.traceback))

        self.add_section('Green Threads', tgen.GreenThreadReportGenerator())

        self.add_section('Configuration', cgen.ConfigReportGenerator())

        try:
            for section_title, generator in self.persistent_sections:
                self.add_section(section_title, generator)
        except AttributeError:
            pass