Skip to content

Commit 1bbe73f

Browse files
committed
Update docs
Update docs
1 parent 1e292c2 commit 1bbe73f

File tree

31 files changed

+2974
-673
lines changed

31 files changed

+2974
-673
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
Callback Executor
2+
=================
3+
4+
The ``CallbackFunctionExecutor`` allows chaining a trigger function with a callback function.
5+
This is useful for post-test workflows — for example, run a test, then automatically
6+
generate a report.
7+
8+
Basic Usage
9+
-----------
10+
11+
.. code-block:: python
12+
13+
from je_load_density import callback_executor
14+
15+
def after_test():
16+
print("Test finished, generating report...")
17+
18+
callback_executor.callback_function(
19+
trigger_function_name="user_test",
20+
callback_function=after_test,
21+
user_detail_dict={"user": "fast_http_user"},
22+
user_count=10,
23+
spawn_rate=5,
24+
test_time=5,
25+
tasks={"get": {"request_url": "http://httpbin.org/get"}},
26+
)
27+
28+
How It Works
29+
------------
30+
31+
1. The ``trigger_function_name`` is looked up in the executor's ``event_dict``
32+
2. The trigger function is executed with the provided ``**kwargs``
33+
3. After the trigger function completes, the ``callback_function`` is called
34+
4. The return value of the trigger function is returned
35+
36+
Available Trigger Functions
37+
---------------------------
38+
39+
.. list-table::
40+
:header-rows: 1
41+
:widths: 30 70
42+
43+
* - Trigger Name
44+
- Function
45+
* - ``user_test``
46+
- ``start_test()`` — Run a load test
47+
* - ``LD_generate_html``
48+
- ``generate_html()`` — Generate HTML fragments
49+
* - ``LD_generate_html_report``
50+
- ``generate_html_report()`` — Generate HTML report file
51+
* - ``LD_generate_json``
52+
- ``generate_json()`` — Generate JSON data
53+
* - ``LD_generate_json_report``
54+
- ``generate_json_report()`` — Generate JSON report files
55+
* - ``LD_generate_xml``
56+
- ``generate_xml()`` — Generate XML strings
57+
* - ``LD_generate_xml_report``
58+
- ``generate_xml_report()`` — Generate XML report files
59+
60+
Passing Parameters to Callbacks
61+
---------------------------------
62+
63+
With keyword arguments (default):
64+
65+
.. code-block:: python
66+
67+
def my_callback(report_name, format_type):
68+
print(f"Generating {format_type} report: {report_name}")
69+
70+
callback_executor.callback_function(
71+
trigger_function_name="user_test",
72+
callback_function=my_callback,
73+
callback_function_param={"report_name": "final", "format_type": "html"},
74+
callback_param_method="kwargs",
75+
user_detail_dict={"user": "fast_http_user"},
76+
user_count=10,
77+
spawn_rate=5,
78+
test_time=5,
79+
tasks={"get": {"request_url": "http://httpbin.org/get"}},
80+
)
81+
82+
With positional arguments:
83+
84+
.. code-block:: python
85+
86+
def my_callback(arg1, arg2):
87+
print(f"Args: {arg1}, {arg2}")
88+
89+
callback_executor.callback_function(
90+
trigger_function_name="user_test",
91+
callback_function=my_callback,
92+
callback_function_param=["value1", "value2"],
93+
callback_param_method="args",
94+
user_detail_dict={"user": "fast_http_user"},
95+
user_count=10,
96+
spawn_rate=5,
97+
test_time=5,
98+
tasks={"get": {"request_url": "http://httpbin.org/get"}},
99+
)
100+
101+
Parameters
102+
----------
103+
104+
.. list-table::
105+
:header-rows: 1
106+
:widths: 25 15 60
107+
108+
* - Parameter
109+
- Type
110+
- Description
111+
* - ``trigger_function_name``
112+
- ``str``
113+
- Name of function in ``event_dict`` to trigger
114+
* - ``callback_function``
115+
- ``Callable``
116+
- Callback function to execute after the trigger
117+
* - ``callback_function_param``
118+
- ``dict`` or ``list`` or ``None``
119+
- Parameters for the callback (dict for kwargs, list for args)
120+
* - ``callback_param_method``
121+
- ``str``
122+
- ``"kwargs"`` (default) or ``"args"``
123+
* - ``**kwargs``
124+
- —
125+
- Parameters passed to the trigger function
126+
127+
Error Handling
128+
--------------
129+
130+
* ``CallbackExecutorException`` is raised if:
131+
132+
* ``trigger_function_name`` is not found in ``event_dict``
133+
* ``callback_param_method`` is not ``"kwargs"`` or ``"args"``

docs/source/En/doc/cli/cli_doc.rst

Lines changed: 97 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,106 @@
1-
CLI
2-
----
1+
CLI (Command Line Interface)
2+
============================
33

4-
We can use the CLI mode to execute the keyword.
5-
json file or execute the folder containing the Keyword.json files.
4+
LoadDensity provides a full command-line interface via ``python -m je_load_density``.
65

7-
The following example is to execute the specified path of the keyword JSON file.
6+
CLI Arguments
7+
-------------
88

9-
.. code-block::
9+
.. list-table::
10+
:header-rows: 1
11+
:widths: 25 10 65
1012

11-
python je_load_density --execute_file "your_file_path"
13+
* - Argument
14+
- Short
15+
- Description
16+
* - ``--execute_file``
17+
- ``-e``
18+
- Execute a single JSON script file
19+
* - ``--execute_dir``
20+
- ``-d``
21+
- Execute all JSON files in a directory
22+
* - ``--execute_str``
23+
- —
24+
- Execute an inline JSON string
25+
* - ``--create_project``
26+
- ``-c``
27+
- Scaffold a new project with templates
1228

29+
Execute a Single JSON File
30+
--------------------------
1331

32+
Run a test defined in a single JSON keyword file:
1433

15-
The following example is to run all keyword JSON files in a specified folder:
34+
.. code-block:: bash
1635
17-
.. code-block::
36+
python -m je_load_density -e test_scenario.json
1837
19-
python je_load_density --execute_dir "your_dir_path"
38+
The JSON file should follow the action list format:
39+
40+
.. code-block:: json
41+
42+
[
43+
["LD_start_test", {
44+
"user_detail_dict": {"user": "fast_http_user"},
45+
"user_count": 50,
46+
"spawn_rate": 10,
47+
"test_time": 5,
48+
"tasks": {
49+
"get": {"request_url": "http://httpbin.org/get"},
50+
"post": {"request_url": "http://httpbin.org/post"}
51+
}
52+
}]
53+
]
54+
55+
Execute All JSON Files in a Directory
56+
-------------------------------------
57+
58+
Run all JSON keyword files in a specified directory recursively:
59+
60+
.. code-block:: bash
61+
62+
python -m je_load_density -d ./test_scripts/
63+
64+
This scans the directory for all ``.json`` files and executes each one sequentially.
65+
66+
Execute an Inline JSON String
67+
-----------------------------
68+
69+
Execute a JSON action list directly as a string:
70+
71+
.. code-block:: bash
72+
73+
python -m je_load_density --execute_str '[["LD_start_test", {"user_detail_dict": {"user": "fast_http_user"}, "user_count": 10, "spawn_rate": 5, "test_time": 5, "tasks": {"get": {"request_url": "http://httpbin.org/get"}}}]]'
74+
75+
.. note::
76+
77+
On **Windows**, inline JSON strings are automatically double-parsed due to shell
78+
escaping differences. The CLI handles this transparently.
79+
80+
Create a Project
81+
----------------
82+
83+
Scaffold a new project with keyword templates and executor scripts:
84+
85+
.. code-block:: bash
86+
87+
python -m je_load_density -c MyProject
88+
89+
This generates a project directory structure:
90+
91+
.. code-block:: text
92+
93+
MyProject/
94+
└── LoadDensity/
95+
├── keyword/
96+
│ ├── keyword1.json
97+
│ └── keyword2.json
98+
└── executor/
99+
├── executor_one_file.py
100+
└── executor_folder.py
101+
102+
Error Handling
103+
--------------
104+
105+
If no valid argument is provided, the CLI raises a ``LoadDensityTestExecuteException``
106+
and exits with code 1. All errors are printed to stderr.

0 commit comments

Comments
 (0)