This commit is contained in:
benoit 2023-08-23 10:19:07 +02:00 committed by Benoit
parent e66e49b111
commit 7f6a03a3cc
2 changed files with 86 additions and 46 deletions

View file

@ -114,14 +114,22 @@ Several options are available:
## Tests ## Tests
The tests are located in `./tests`. For ease of coding, they are mocked. The Crafting repeatable tests using a live Patroni cluster can be intricate. To
json files are in `./tests/json`. There is an evident drawback, if the json is simplify the development process, interactions with Patroni's API are
wrong or modifications have been made in patroni but not reported here: the substituted with a mock function that yields an HTTP return code and a JSON
tests still work fine. object outlining the cluster's status. The JSON files containing this
information are housed in the ./tests/json directory.
An important consideration is that there is a potential drawback: if the JSON
data is incorrect or if modifications have been made to Patroni without
corresponding updates to the tests documented here, the tests might still pass
erroneously.
To run the tests: To run the tests:
1) download check_patroni, create a virtual env and install the script: 1. Clone the `check_patroni` repository, create a virtual environment, and
install the script:
```bash ```bash
git clone https://github.com/dalibo/check_patroni.git git clone https://github.com/dalibo/check_patroni.git
cd check_patroni cd check_patroni
@ -130,19 +138,31 @@ python -m venv .venv
pip install -e check_patroni[test] pip install -e check_patroni[test]
``` ```
2) run the tests 2) Run the tests
- Using patroni's nominal replica state of `streaming` (since v3.0.4):
```bash ```bash
pytest ./tests # nominal replica state is streaming (since v3.0.4) pytest ./tests
pytest --use-old-replica-state ./tests # nominal replica state is running
``` ```
Note: for any service that checks the state of a node in the `cluster` endpoint, - Using patroni's nominal replica state of `running` (before v3.0.4):
the json test file must be added in `./test/tools.py`.
A bash script is provided to perform all tests on a patroni endpoint ```bash
(`./vagrant/check_patroni.sh`), it takes one parameter: the endpoint pytest --use-old-replica-state ./tests
we give to the `-e/--endpoints` of check_patroni. Nothing fancy, it's ```
just a list of all service calls in a bash script.
Please note that when dealing with any service that checks the state of a node
in patroni's `cluster` endpoint, the corresponding JSON test file must be added
in `./test/tools.py`.
A bash script, `check_patroni.sh`, is provided to facilitate testing all
services on a Patroni endpoint (`./vagrant/check_patroni.sh`). It requires one
parameter: the endpoint URL that will be used as the argument for the
`-e/--endpoints` option of `check_patroni`. This script essentially compiles a
list of service calls and executes them sequentially in a bash script.
Here's an example usage:
```bash ```bash
./vagrant/check_patroni.sh http://10.20.30.51:8008 ./vagrant/check_patroni.sh http://10.20.30.51:8008

View file

@ -98,14 +98,22 @@ Several options are available:
## Tests ## Tests
The tests are located in `./tests`. For ease of coding, they are mocked. The Crafting repeatable tests using a live Patroni cluster can be intricate. To
json files are in `./tests/json`. There is an evident drawback, if the json is simplify the development process, interactions with Patroni's API are
wrong or modifications have been made in patroni but not reported here: the substituted with a mock function that yields an HTTP return code and a JSON
tests still work fine. object outlining the cluster's status. The JSON files containing this
information are housed in the ./tests/json directory.
An important consideration is that there is a potential drawback: if the JSON
data is incorrect or if modifications have been made to Patroni without
corresponding updates to the tests documented here, the tests might still pass
erroneously.
To run the tests: To run the tests:
1) download check_patroni, create a virtual env and install the script: 1. Clone the `check_patroni` repository, create a virtual environment, and
install the script:
```bash ```bash
git clone https://github.com/dalibo/check_patroni.git git clone https://github.com/dalibo/check_patroni.git
cd check_patroni cd check_patroni
@ -114,19 +122,31 @@ python -m venv .venv
pip install -e check_patroni[test] pip install -e check_patroni[test]
``` ```
2) run the tests 2) Run the tests
- Using patroni's nominal replica state of `streaming` (since v3.0.4):
```bash ```bash
pytest ./tests # nominal replica state is streaming (since v3.0.4) pytest ./tests
pytest --use-old-replica-state ./tests # nominal replica state is running
``` ```
Note: for any service that checks the state of a node in the `cluster` endpoint, - Using patroni's nominal replica state of `running` (before v3.0.4):
the json test file must be added in `./test/tools.py`.
A bash script is provided to perform all tests on a patroni endpoint ```bash
(`./vagrant/check_patroni.sh`), it takes one parameter: the endpoint pytest --use-old-replica-state ./tests
we give to the `-e/--endpoints` of check_patroni. Nothing fancy, it's ```
just a list of all service calls in a bash script.
Please note that when dealing with any service that checks the state of a node
in patroni's `cluster` endpoint, the corresponding JSON test file must be added
in `./test/tools.py`.
A bash script, `check_patroni.sh`, is provided to facilitate testing all
services on a Patroni endpoint (`./vagrant/check_patroni.sh`). It requires one
parameter: the endpoint URL that will be used as the argument for the
`-e/--endpoints` option of `check_patroni`. This script essentially compiles a
list of service calls and executes them sequentially in a bash script.
Here's an example usage:
```bash ```bash
./vagrant/check_patroni.sh http://10.20.30.51:8008 ./vagrant/check_patroni.sh http://10.20.30.51:8008