MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_context_threads_1

Method test_context_threads_1

Lib/test/test_context.py:359–374  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

357 @threading_helper.requires_working_threading()
358 @unittest.skipIf(sys.platform == 'darwin', 'TODO: RUSTPYTHON; Flaky on Mac, self.assertEqual(cvar.get(), num + i) AssertionError: 8 != 12')
359 def test_context_threads_1(self):
360 cvar = contextvars.ContextVar('cvar')
361
362 def sub(num):
363 for i in range(10):
364 cvar.set(num + i)
365 time.sleep(random.uniform(0.001, 0.05))
366 self.assertEqual(cvar.get(), num + i)
367 return num
368
369 tp = concurrent.futures.ThreadPoolExecutor(max_workers=10)
370 try:
371 results = list(tp.map(sub, range(10)))
372 finally:
373 tp.shutdown()
374 self.assertEqual(results, list(range(10)))
375
376
377# HAMT Tests

Callers

nothing calls this directly

Calls 4

shutdownMethod · 0.95
listClass · 0.85
mapMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected