Skip to content

Commit 6176468

Browse files
committed
docs: Add reference/testserver.md to document the gl-testserver
1 parent 48b05f6 commit 6176468

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

docs/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ nav:
8383
- Client Libraries: reference/client-libraries.md
8484
- Credentials: reference/creds.md
8585
- reference/node-domain.md
86+
- Testserver: reference/testserver.md
8687
- Certificates: reference/certs.md
8788
- Security: reference/security.md
8889
- LSP Integration: reference/lsp.md

docs/src/reference/testserver.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# The `gl-testserver`
2+
3+
The `gl-testserver` is a standalone version, of the `gl-testing`
4+
framework, allowing you to test against a mock Greenlight server,
5+
independently of your programming language and development
6+
environment.
7+
8+
The goal of the `gl-testing` package is to enable developers to test
9+
locally against a mock Greenlight server. This has a number of
10+
advantages:
11+
12+
- **Speed**: by not involving the network, you can test without
13+
latency slowing you down. The tests also run on a `regtest`
14+
network, allowing you to generate blocks and confirm transactions
15+
without the need to wait.
16+
- **Cost**: the `prod` network is not free, and since tests may
17+
consume arbitrary resources, which are then not cleaned up (see
18+
next point), repeatedly running them could incur costs. We see this
19+
as a bad incentive to minimize testing during development, and
20+
`gl-testing` allows you to use only local resources that can then
21+
also be reclaimed, making testing free, and hopefully encouraging
22+
to test more.
23+
- **Reproducibility**: The `prod` network does not allow cleaning up
24+
test resources, since there might be an actual user using
25+
them. This means that test artifacts persist between runs,
26+
resulting in a non-reproducible environment for
27+
testing. `gl-testing` running locally allows cleaning up resources,
28+
thus enabling reproducible tests.
29+
30+
However, the downside of `gl-testing` is that is coupled with `python`
31+
as programming language and `pytest` as test runner. This is where
32+
`gl-testserver` comes in: by bundling all the fixtures and startup
33+
logic into a standalone binary we can pull up an instance in a matter
34+
of seconds, test and develop against it, and then tear it down at the
35+
end of our session.
36+
37+
## How to use `gl-testserver`
38+
39+
It's probably easiest to use `uv` to run the script from the source
40+
tree. Please see the [`uv` installation instructions][uv/install] for
41+
how to get started installing `uv` then come back here.
42+
43+
Executing `uv run gltestserver` is the entrypoint for the tool:
44+
45+
```bash
46+
gltestserver
47+
Usage: gltestserver [OPTIONS] COMMAND [ARGS]...
48+
49+
Options:
50+
--help Show this message and exit.
51+
52+
Commands:
53+
run Start a gl-testserver instance to test against.
54+
```
55+
56+
Currently there is only the `run` subcommand which will start the
57+
testserver, binding the scheduler GRPC interface, the `bitcoind` RPC
58+
interface, and the GRPC-web proxy to random ports on `localhost`.
59+
60+
61+
```bash
62+
gltestserver run --help
63+
Usage: gltestserver run [OPTIONS]
64+
65+
Start a gl-testserver instance to test against.
66+
67+
Options:
68+
--directory PATH Set the top-level directory for the testserver. This can
69+
be used to run multiple instances isolated from each
70+
other, by giving each isntance a different top-level
71+
directory. Defaults to '/tmp/'
72+
--help Show this message and exit
73+
```
74+
75+
In order to identify the ports for the current instance you can either
76+
see the end of the output of the command, which contains
77+
pretty-printed key-value pairs, or load the `metadata.json` file
78+
containing the port references to use from the `gl-testserver`
79+
sub-directory (`/tmp/gl-testserver` if you haven't specified the
80+
`--directory` option).
81+
82+
!!! note "Running multiple tests in parallel"
83+
As the help text above already points out it is possible to run as many
84+
instances of the testserver concurrently as you want, by specifying
85+
separate `--directory` options in each call.
86+
87+
This is particularly useful if you want to run multiple tests in parallel
88+
to speed up the test runs. It is also the core reason why ports are
89+
randomized rather than using fixed ports per interface, as concurrent
90+
instances would conflict, and the isolation between tests could be
91+
compromised.
92+
93+
Once started you will see the following lines printed:
94+
95+
```
96+
Writing testserver metadata to /tmp/gl-testserver/metadata.json
97+
{
98+
'scheduler_grpc_uri': 'https://localhost:38209',
99+
'grpc_web_proxy_uri': 'http://localhost:35911',
100+
'bitcoind_rpc_uri': 'http://rpcuser:rpcpass@localhost:44135'
101+
}
102+
Server is up and running with the above config values. To stop press Ctrl-C.
103+
```
104+
105+
At this point you can use the URIs that are printed to interact with
106+
the services, or use `Ctrl-C` to stop the server. When running in a
107+
test environment you can send `SIGTERM` to the process and it'll also
108+
shut down gracefully, cleaning up the processes, but leaving the data
109+
created during the test in the directory.
110+
111+
[uv/install]: https://docs.astral.sh/uv/getting-started/installation/

0 commit comments

Comments
 (0)