(self)
| 149 | |
| 150 | @threading_helper.requires_working_threading() |
| 151 | def test_module_load_race(self): |
| 152 | with test_util.uncache(TestingImporter.module_name): |
| 153 | loader = TestingImporter() |
| 154 | module = self.new_module(loader=loader) |
| 155 | self.assertEqual(loader.load_count, 0) |
| 156 | |
| 157 | class RaisingThread(threading.Thread): |
| 158 | exc = None |
| 159 | def run(self): |
| 160 | try: |
| 161 | super().run() |
| 162 | except Exception as exc: |
| 163 | self.exc = exc |
| 164 | |
| 165 | def access_module(): |
| 166 | return module.attr |
| 167 | |
| 168 | threads = [] |
| 169 | for _ in range(2): |
| 170 | threads.append(thread := RaisingThread(target=access_module)) |
| 171 | thread.start() |
| 172 | |
| 173 | # Races could cause errors |
| 174 | for thread in threads: |
| 175 | thread.join() |
| 176 | self.assertIsNone(thread.exc) |
| 177 | |
| 178 | # Or multiple load attempts |
| 179 | self.assertEqual(loader.load_count, 1) |
| 180 | |
| 181 | def test_lazy_self_referential_modules(self): |
| 182 | # Directory modules with submodules that reference the parent can attempt to access |
nothing calls this directly
no test coverage detected