Skip to content

Commit

Permalink
Merge pull request #19 from tair-opensource/feature-docs
Browse files Browse the repository at this point in the history
Update docs and add http server
  • Loading branch information
yangbodong22011 authored Aug 30, 2023
2 parents 38df86f + 8dd0998 commit 98eae25
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
41 changes: 35 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,46 @@ optional arguments:
--ssl open ssl connection
--genhtml generate test report in html format
```

Examples:
Test whether host:port is compatible with redis 6.2.0 and display failure case:
e.g. Test whether host:port is compatible with redis 6.2.0 and display failure case:
```
$ python3 redis_compatibility_test.py -h host -p port --testfile cts.json --specific-version 6.2.0 --show-failed
Connecting to 127.0.0.1:6379 use standalone client
test: del command passed
test: unlink command passed
...
test: rpushx with multiple element passed
test: xtrim command with MINID/LIMIT passed
-------- The result of tests --------
Summary: version: 6.2.0, total tests: 285, passed: 285, rate: 100.00%
```
More examples are shown `python3 redis_compatibility_test.py -h`.

## cluster
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:
```
$ python3.9 redis_compatibility_test.py --testfile cts.json --host 127.0.0.1 --port 30001 --cluster --specific-version 6.2.0
connecting to 127.0.0.1:30001 use cluster client
test: del command passed
test: unlink command passed
...
test: xtrim command with MINID/LIMIT passed
-------- The result of tests --------
version: 6.2.0, total tests: 62, passed: 62, rate: 100.0%
Summary: version: 6.2.0, total tests: 260, passed: 260, rate: 100.00%
```

## genhtml
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.
```
$ python3.9 redis_compatibility_test.py --testfile cts.json --genhtml --show-failed
directory html already exists, will be deleted and renewed.
start test Redis for version 4.0.0
connecting to 127.0.0.1:6379 using standalone client
start test Redis for version 5.0.0
connecting to 127.0.0.1:6379 using standalone client
start test Redis for version 6.0.0
connecting to 127.0.0.1:6379 using standalone client
start test Redis for version 7.0.0
connecting to 127.0.0.1:6379 using standalone client
...
Visit http://localhost:8000 for the report.
```
More examples are shown `python3 redis_compatibility_test.py -h`.
Then, an Http Server will be started on http://localhost:8000 by default, and you can access it to get reports.
14 changes: 13 additions & 1 deletion redis_compatibility_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import argparse
import os
import re
import http.server
import socketserver

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


def start_webserver(logdir):
os.chdir(logdir)
handler = http.server.SimpleHTTPRequestHandler
httpd = http.server.HTTPServer(('', 8000), handler)
httpd.directory = logdir
print(f"Visit http://localhost:8000 for the report.")
httpd.serve_forever()


def run_test_by_configfile():
global logfile
try:
Expand Down Expand Up @@ -299,6 +310,7 @@ def run_test_by_configfile():
logfile = None
# now we generate index.html
generate_html_report(logdir, configs)
start_webserver(logdir)


def create_client(host, port, password, ssl, cluster):
Expand Down

0 comments on commit 98eae25

Please sign in to comment.