Add context_id to py_func and lua_func for shared persistent subprocess
- py_func and lua_func items accept a context_id parameter; items sharing the same id reuse the same subprocess for the duration of the test run - Subprocess-side tm.setgd/tm.gd use a local fallback dict for non-JSON- serializable values (py_func only); serializable values reach the main process global dict and are accessible from any test item or subprocess - Shared subprocess engines are cleaned up in process.py finally block - LuaProcessBase gains is_alive() (was missing, broke all lua_func items) - Validation tests cover serializable sharing across different context ids, non-serializable sharing within the same context_id, and cross-item access - RST documentation updated for both py_func and lua_func items Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -32,5 +32,13 @@ function module.tuple_return(first, second)
|
||||
return first, second
|
||||
end
|
||||
|
||||
function module.set_context_value(val)
|
||||
tm.setgd("_lua_ctx_test_value", val)
|
||||
return val
|
||||
end
|
||||
|
||||
function module.get_context_value()
|
||||
return tm.gd("_lua_ctx_test_value")
|
||||
end
|
||||
|
||||
return module
|
||||
@@ -179,3 +179,36 @@
|
||||
file: $(test_path)$(psep)lua_func.lua
|
||||
func_name: tuple_return
|
||||
param: [ 0, "OK" ]
|
||||
|
||||
- group:
|
||||
name: context_id tests
|
||||
steps:
|
||||
- lua_func:
|
||||
name: set context value
|
||||
key: $(test)_PASS
|
||||
file: $(test_path)$(psep)lua_func.lua
|
||||
func_name: set_context_value
|
||||
context_id: lua_ctx_test
|
||||
param:
|
||||
- hello lua
|
||||
expected_result: hello lua
|
||||
- lua_func:
|
||||
name: get context value (same context_id)
|
||||
key: $(test)_PASS
|
||||
file: $(test_path)$(psep)lua_func.lua
|
||||
func_name: get_context_value
|
||||
context_id: lua_ctx_test
|
||||
expected_result: hello lua
|
||||
- lua_func:
|
||||
name: get context value (no context_id, from main gd)
|
||||
key: $(test)_PASS
|
||||
file: $(test_path)$(psep)lua_func.lua
|
||||
func_name: get_context_value
|
||||
expected_result: hello lua
|
||||
- lua_func:
|
||||
name: get context value (different context_id)
|
||||
key: $(test)_PASS
|
||||
file: $(test_path)$(psep)lua_func.lua
|
||||
func_name: get_context_value
|
||||
context_id: lua_ctx_other
|
||||
expected_result: hello lua
|
||||
|
||||
@@ -27,3 +27,23 @@ def echo(param):
|
||||
|
||||
def tuple_return(first, second):
|
||||
return first, second
|
||||
|
||||
def set_context_value(val):
|
||||
tm.setgd("_py_ctx_test_value", val)
|
||||
return val
|
||||
|
||||
def get_context_value():
|
||||
return tm.gd("_py_ctx_test_value", None)
|
||||
|
||||
|
||||
class _NotSerializable:
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
def set_ns_value(val):
|
||||
tm.setgd("_py_ctx_ns_value", _NotSerializable(val))
|
||||
return val
|
||||
|
||||
def get_ns_value():
|
||||
obj = tm.gd("_py_ctx_ns_value", None)
|
||||
return obj.val if obj is not None else None
|
||||
|
||||
@@ -189,3 +189,51 @@
|
||||
func_name: tuple_return
|
||||
param: [ 0, "OK" ]
|
||||
expected_result: [0, "OK"]
|
||||
|
||||
- group:
|
||||
name: context_id tests
|
||||
steps:
|
||||
- py_func:
|
||||
name: set serializable value
|
||||
key: $(test)_PASS
|
||||
file: $(test_path)$(psep)py_func.py
|
||||
func_name: set_context_value
|
||||
param:
|
||||
- hello context
|
||||
expected_result: hello context
|
||||
- py_func:
|
||||
name: get serializable value (same context_id)
|
||||
key: $(test)_PASS
|
||||
file: $(test_path)$(psep)py_func.py
|
||||
func_name: get_context_value
|
||||
context_id: ctx_test
|
||||
expected_result: hello context
|
||||
- py_func:
|
||||
name: get serializable value (no context_id, from main gd)
|
||||
key: $(test)_PASS
|
||||
file: $(test_path)$(psep)py_func.py
|
||||
func_name: get_context_value
|
||||
expected_result: hello context
|
||||
- py_func:
|
||||
name: get serializable value (different context_id)
|
||||
key: $(test)_PASS
|
||||
file: $(test_path)$(psep)py_func.py
|
||||
func_name: get_context_value
|
||||
context_id: ctx_other
|
||||
expected_result: hello context
|
||||
- py_func:
|
||||
name: set non-serializable value
|
||||
key: $(test)_PASS
|
||||
file: $(test_path)$(psep)py_func.py
|
||||
func_name: set_ns_value
|
||||
context_id: ctx_ns_test
|
||||
param:
|
||||
- hello ns
|
||||
expected_result: hello ns
|
||||
- py_func:
|
||||
name: get non-serializable value (same context_id)
|
||||
key: $(test)_PASS
|
||||
file: $(test_path)$(psep)py_func.py
|
||||
func_name: get_ns_value
|
||||
context_id: ctx_ns_test
|
||||
expected_result: hello ns
|
||||
|
||||
Reference in New Issue
Block a user