Skip to content

Commit 98eae25

Browse files
Merge pull request #19 from tair-opensource/feature-docs
Update docs and add http server
2 parents 38df86f + 8dd0998 commit 98eae25

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

README.md

+35-6
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,46 @@ optional arguments:
2929
--ssl open ssl connection
3030
--genhtml generate test report in html format
3131
```
32-
33-
Examples:
34-
Test whether host:port is compatible with redis 6.2.0 and display failure case:
32+
e.g. Test whether host:port is compatible with redis 6.2.0 and display failure case:
3533
```
3634
$ python3 redis_compatibility_test.py -h host -p port --testfile cts.json --specific-version 6.2.0 --show-failed
3735
Connecting to 127.0.0.1:6379 use standalone client
3836
test: del command passed
3937
test: unlink command passed
4038
...
41-
test: rpushx with multiple element passed
39+
test: xtrim command with MINID/LIMIT passed
40+
-------- The result of tests --------
41+
Summary: version: 6.2.0, total tests: 285, passed: 285, rate: 100.00%
42+
```
43+
More examples are shown `python3 redis_compatibility_test.py -h`.
44+
45+
## cluster
46+
Redis has two modes from the API level, namely `Standalone` (Sentinel has no API restrictions like Standalone) and `Cluster`, where the command support of Standalone does not require Cross slot, but Cluster restricts multi-key commands to be executed in the same slot (e.g. mset/mget ), therefore, we support `--cluster` to test the compatibility of cluster mode, you can test your Redis Cluster cluster compatibility as follows:
47+
```
48+
$ python3.9 redis_compatibility_test.py --testfile cts.json --host 127.0.0.1 --port 30001 --cluster --specific-version 6.2.0
49+
connecting to 127.0.0.1:30001 use cluster client
50+
test: del command passed
51+
test: unlink command passed
52+
...
53+
test: xtrim command with MINID/LIMIT passed
4254
-------- The result of tests --------
43-
version: 6.2.0, total tests: 62, passed: 62, rate: 100.0%
55+
Summary: version: 6.2.0, total tests: 260, passed: 260, rate: 100.00%
56+
```
57+
58+
## genhtml
59+
You can use `--genhtml` to generate a test report similar to the html of this [website](https://tair-opensource.github.io/compatibility-test-suite-for-redis/). It should be noted that this option will read the configuration in [config.yaml](config.yaml) for testing. Special attention needs to be paid, at this time the `specific-version` specified in your command line will be overwritten by the one in the configuration file.
60+
```
61+
$ python3.9 redis_compatibility_test.py --testfile cts.json --genhtml --show-failed
62+
directory html already exists, will be deleted and renewed.
63+
start test Redis for version 4.0.0
64+
connecting to 127.0.0.1:6379 using standalone client
65+
start test Redis for version 5.0.0
66+
connecting to 127.0.0.1:6379 using standalone client
67+
start test Redis for version 6.0.0
68+
connecting to 127.0.0.1:6379 using standalone client
69+
start test Redis for version 7.0.0
70+
connecting to 127.0.0.1:6379 using standalone client
71+
...
72+
Visit http://localhost:8000 for the report.
4473
```
45-
More examples are shown `python3 redis_compatibility_test.py -h`.
74+
Then, an Http Server will be started on http://localhost:8000 by default, and you can access it to get reports.

redis_compatibility_test.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import argparse
33
import os
44
import re
5+
import http.server
6+
import socketserver
57

68
import redis
79
import json
@@ -217,7 +219,7 @@ def generate_html_report(logdir, configs):
217219
filepath = f"{logdir}/index.html"
218220
html = open(filepath, "w")
219221
html.write("This page is automatically generated by <a href=\"https://github.com/tair-opensource/"
220-
"compatibility-test-suite-for-redis\">compatibility-test-suite-for-redis</a>"
222+
"compatibility-test-suite-for-redis\">compatibility-test-suite-for-redis</a> "
221223
"to show the compatibility of the following Redis-Like systems and different versions of Redis.<br><br>")
222224
html.write("<table>")
223225
# generate header
@@ -259,6 +261,15 @@ def generate_html_report(logdir, configs):
259261
html.close()
260262

261263

264+
def start_webserver(logdir):
265+
os.chdir(logdir)
266+
handler = http.server.SimpleHTTPRequestHandler
267+
httpd = http.server.HTTPServer(('', 8000), handler)
268+
httpd.directory = logdir
269+
print(f"Visit http://localhost:8000 for the report.")
270+
httpd.serve_forever()
271+
272+
262273
def run_test_by_configfile():
263274
global logfile
264275
try:
@@ -299,6 +310,7 @@ def run_test_by_configfile():
299310
logfile = None
300311
# now we generate index.html
301312
generate_html_report(logdir, configs)
313+
start_webserver(logdir)
302314

303315

304316
def create_client(host, port, password, ssl, cluster):

0 commit comments

Comments
 (0)