MCPcopy Create free account
hub / github.com/MemTensor/MemOS / test_context_thread_pool_propagation

Function test_context_thread_pool_propagation

tests/api/test_thread_context.py:51–72  ·  view source on GitHub ↗

Test if ContextThreadPoolExecutor correctly propagates context to worker threads

()

Source from the content-addressed store, hash-verified

49
50
51def 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
75def test_context_thread_pool_map_propagation():

Callers

nothing calls this directly

Calls 4

RequestContextClass · 0.90
set_request_contextFunction · 0.90
submitMethod · 0.80

Tested by

no test coverage detected