Test if ContextThreadPoolExecutor correctly propagates context to worker threads
()
| 49 | |
| 50 | |
| 51 | def test_context_thread_pool_propagation(): |
| 52 | """Test if ContextThreadPoolExecutor correctly propagates context to worker threads""" |
| 53 | # Set up main thread context |
| 54 | main_context = RequestContext(trace_id="pool-test-trace") |
| 55 | main_context.test_data = "pool test value" |
| 56 | set_request_context(main_context) |
| 57 | |
| 58 | def pool_task(): |
| 59 | context = get_current_context() |
| 60 | return { |
| 61 | "trace_id": context.trace_id if context else None, |
| 62 | "test_data": context.test_data if context else None, |
| 63 | } |
| 64 | |
| 65 | # Use thread pool to execute task |
| 66 | with ContextThreadPoolExecutor(max_workers=2) as executor: |
| 67 | future = executor.submit(pool_task) |
| 68 | result = future.result() |
| 69 | |
| 70 | # Verify context propagation |
| 71 | assert result["trace_id"] == "pool-test-trace" |
| 72 | assert result["test_data"] == "pool test value" |
| 73 | |
| 74 | |
| 75 | def test_context_thread_pool_map_propagation(): |
nothing calls this directly
no test coverage detected