Skip to content

Commit

Permalink
doc: Add GENERATE_EXAMPLES details
Browse files Browse the repository at this point in the history
Changelog-None.
  • Loading branch information
ShahanaFarooqui authored and rustyrussell committed Nov 28, 2024
1 parent 0a7956b commit 075f180
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ To add conditional fields:
generate the Markdown syntax as `[*index* [*start*] [*limit*]]`.

## Generating Examples in Schema
The `tests/autogenerate-rpc-examples.py` test script regenerates RPC examples for methods defined
in `doc/schemas/lightning-*.json`. These examples are located at the end of each schema page,
detailing `shell` and `json` request formats along with their corresponding `json` responses.
The script utilizes the pytest suite to automate this task by running a test, `test_generate_examples`,
that sets up test nodes, records RPC requests, and captures responses. Any new RPC command's examples
should also be included in this scripts. This test only executes example generation if `GENERATE_EXAMPLES=True`
is set, preventing accidental overwrites from unrelated tests.
The `tests/autogenerate-rpc-examples.py` test script regenerates RPC examples for methods defined
in `doc/schemas/lightning-*.json`, if the environment variable `GENERATE_EXAMPLES` is set to 1.
These examples are located at the end of each schema page, detailing `shell` and `json` request
formats along with their corresponding `json` responses. The script utilizes the pytest suite to
automate this task by running a test, `test_generate_examples`, that sets up test nodes, records
RPC requests, and captures responses. Any new RPC command's examples should also be included in
this scripts. This test only executes example generation if `GENERATE_EXAMPLES=1` is set,
preventing accidental overwrites from unrelated tests.

### Adding New Examples
1. Define a New Function (if needed):
Expand All @@ -93,7 +94,7 @@ is set, preventing accidental overwrites from unrelated tests.
where `n` can be any number of repetitions. OR by manually running the test multiple times with:

```bash
rm -rf /tmp/ltests* && make -s && VALGRIND=0 TIMEOUT=40 TEST_DEBUG=1 pytest -vvv -n 6 tests/autogenerate-rpc-examples.py
rm -rf /tmp/ltests* && make -s && VALGRIND=0 TIMEOUT=40 TEST_DEBUG=1 GENERATE_EXAMPLES=1 pytest -vvv tests/autogenerate-rpc-examples.py
```

- Identify changing values, and add them to `REPLACE_RESPONSE_VALUES`:
Expand All @@ -116,7 +117,7 @@ environment variable with a comma-separated list of method names. Eg. `REGENERAT
only regenerate examples for the `getinfo` and `connect` RPCs.
2. To regenerate specific examples, set the REGENERATE environment variable:
```bash
REGENERATE='getinfo,connect' VALGRIND=0 TIMEOUT=10 TEST_DEBUG=1 pytest -vvv -n 6 tests/autogenerate-rpc-examples.py
REGENERATE='getinfo,connect' VALGRIND=0 TIMEOUT=10 TEST_DEBUG=1 GENERATE_EXAMPLES=1 pytest -vvv tests/autogenerate-rpc-examples.py
```
3. Logs are saved in `tests/autogenerate-examples-status.log`, and JSON data is in `tests/autogenerate-examples.json`.
4. Run `make` after the script completes to ensure schema updates are applied in other places too, such as `...msggen/schema.json`.
Expand Down
1 change: 1 addition & 0 deletions doc/contribute-to-core-lightning/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ PYTEST_TESTS="tests/" - Target a specific set of blackbox tests
SLOW_MACHINE=[0|1] - Set sensible defaults for running tests
in resource-constrained environments.
VALGRIND=[0|1] - Run the tests with Valgrind.
GENERATE_EXAMPLES=[0|1] - Generate examples for RPC documentation.
```

#### Troubleshooting
Expand Down

0 comments on commit 075f180

Please sign in to comment.