Skip to content

Commit 422252c

Browse files
Merge pull request #176 from RedisLabs/testing.infra
Moved integration testing logic out of github actions and included testing section on Readme
2 parents 659b248 + 6ddf197 commit 422252c

File tree

7 files changed

+291
-76
lines changed

7 files changed

+291
-76
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,99 +14,54 @@ jobs:
1414
run: |
1515
sudo apt-get -qq update
1616
sudo apt-get install autoconf automake pkg-config libevent-dev libpcre3-dev libssl-dev
17+
1718
- name: Build
18-
run: autoreconf -ivf && ./configure && make
19+
run: autoreconf -ivf && ./configure && make -j
1920
- name: Setup Python
20-
uses: actions/setup-python@v1
21+
uses: actions/setup-python@v2
2122
with:
2223
python-version: '3.6'
24+
architecture: x64
2325

24-
- name: Cache pip
25-
uses: actions/cache@v1
26-
with:
27-
path: ~/.cache/pip # This path is specific to Ubuntu
28-
# Look to see if there is a cache hit for the corresponding requirements file
29-
key: ${{ runner.os }}-pip-${{ hashFiles('tests/test_requirements.txt') }}
30-
restore-keys: |
31-
${{ runner.os }}-pip-
32-
${{ runner.os }}-
3326
- name: Install Python dependencies
34-
run: pip install -r tests/test_requirements.txt
35-
36-
- name: Cache Redis
37-
id: cache-redis
38-
uses: actions/cache@v1
39-
with:
40-
path: /home/runner/work/memtier_benchmark/memtier_benchmark/redis
41-
key: ${{ runner.os }}-redis
27+
run: pip install -r ./tests/test_requirements.txt
4228

43-
- name: Check out Redis
44-
if: steps.cache-redis.outputs.cache-hit != 'true'
45-
uses: actions/checkout@v3
46-
with:
47-
repository: 'redis/redis'
48-
ref: 'unstable'
49-
path: 'redis'
29+
- name: Install Redis
30+
run: |
31+
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
32+
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
33+
sudo apt-get -qq update
34+
sudo apt-get install redis
35+
sudo service redis-server stop
5036
51-
- name: Build and run Redis
52-
if: steps.cache-redis.outputs.cache-hit != 'true'
37+
- name: Generate TLS test certificates
38+
if: matrix.platform == 'ubuntu-latest'
5339
run: |
54-
cd redis
55-
make BUILD_TLS=yes
56-
./utils/gen-test-certs.sh
57-
./src/redis-server --version
40+
./tests/gen-test-certs.sh
5841
5942
- name: Test OSS TCP
43+
timeout-minutes: 10
6044
run: |
61-
cd tests
62-
MEMTIER_BINARY=./../memtier_benchmark \
63-
python3 -m RLTest \
64-
--env oss -v --clear-logs \
65-
--oss-redis-path ../redis/src/redis-server
66-
cd ..
45+
./tests/run_tests.sh
6746
6847
- name: Test OSS TCP TLS
6948
if: matrix.platform == 'ubuntu-latest'
49+
timeout-minutes: 10
7050
run: |
71-
cd tests
72-
TLS_CERT=../redis/tests/tls/redis.crt \
73-
TLS_KEY=../redis/tests/tls/redis.key \
74-
TLS_CACERT=../redis/tests/tls/ca.crt \
75-
MEMTIER_BINARY=../memtier_benchmark \
76-
python3 -m RLTest \
77-
--env oss -v --clear-logs \
78-
--oss-redis-path ../redis/src/redis-server \
79-
--tls-cert-file ../redis/tests/tls/redis.crt \
80-
--tls-key-file ../redis/tests/tls/redis.key \
81-
--tls-ca-cert-file ../redis/tests/tls/ca.crt \
82-
--tls
83-
cd ..
51+
TLS=1 ./tests/run_tests.sh
8452
8553
- name: Test OSS-CLUSTER TCP
54+
timeout-minutes: 10
8655
run: |
87-
cd tests
88-
MEMTIER_BINARY=./../memtier_benchmark \
89-
python3 -m RLTest \
90-
--env oss-cluster -v --clear-logs --shards-count 3 \
91-
--oss-redis-path ../redis/src/redis-server
92-
cd ..
56+
OSS_STANDALONE=0 OSS_CLUSTER=1 \
57+
./tests/run_tests.sh
9358
9459
- name: Test OSS-CLUSTER TCP TLS
60+
timeout-minutes: 10
9561
if: matrix.platform == 'ubuntu-latest'
9662
run: |
97-
cd tests
98-
TLS_CERT=../redis/tests/tls/redis.crt \
99-
TLS_KEY=../redis/tests/tls/redis.key \
100-
TLS_CACERT=../redis/tests/tls/ca.crt \
101-
MEMTIER_BINARY=../memtier_benchmark \
102-
python3 -m RLTest \
103-
--env oss-cluster --shards-count 3 -v --clear-logs \
104-
--oss-redis-path ../redis/src/redis-server \
105-
--tls-cert-file ../redis/tests/tls/redis.crt \
106-
--tls-key-file ../redis/tests/tls/redis.key \
107-
--tls-ca-cert-file ../redis/tests/tls/ca.crt \
108-
--tls
109-
cd ..
63+
OSS_STANDALONE=0 OSS_CLUSTER=1 TLS=1 \
64+
./tests/run_tests.sh
11065
11166
build-macos:
11267
strategy:

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ stamp-h1
2525
.vscode/*
2626
.idea/*
2727

28+
# tls helper related files
29+
tests/tls/*
30+
2831
# memtier outputs
2932
*.hgrm
3033
*.txt
34+
!/tests/test_requirements.txt
3135
__pycache__

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,30 @@ $ make
101101
$ make install
102102
```
103103

104+
#### Testing
105+
106+
The project includes a basic set of integration tests.
107+
108+
109+
**Integration tests**
110+
111+
112+
Integration tests are based on [RLTest](https://github.com/RedisLabsModules/RLTest), and specific setup parameters can be provided
113+
to configure tests and topologies (OSS standalone and OSS cluster). By default the tests will be ran for all common commands, and with OSS standalone setup.
114+
115+
116+
To run all integration tests in a Python virtualenv, follow these steps:
117+
118+
$ mkdir -p .env
119+
$ virtualenv .env
120+
$ source .env/bin/activate
121+
$ pip install -r tests/test_requirements.txt
122+
$ ./tests/run_tests.sh
123+
124+
To understand what test options are available simply run:
125+
126+
$ ./tests/run_tests.sh --help
127+
104128
## Using Docker
105129

106130
Use available images on Docker Hub:

tests/gen-test-certs.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
# Generate some test certificates which are used by the regression test suite:
4+
#
5+
# tests/tls/ca.{crt,key} Self signed CA certificate.
6+
# tests/tls/redis.{crt,key} A certificate with no key usage/policy restrictions.
7+
# tests/tls/client.{crt,key} A certificate restricted for SSL client usage.
8+
# tests/tls/server.{crt,key} A certificate restricted for SSL server usage.
9+
# tests/tls/redis.dh DH Params file.
10+
11+
generate_cert() {
12+
local name=$1
13+
local cn="$2"
14+
local opts="$3"
15+
16+
local keyfile=tests/tls/${name}.key
17+
local certfile=tests/tls/${name}.crt
18+
19+
[ -f $keyfile ] || openssl genrsa -out $keyfile 2048
20+
openssl req \
21+
-new -sha256 \
22+
-subj "/O=Redis Test/CN=$cn" \
23+
-key $keyfile | \
24+
openssl x509 \
25+
-req -sha256 \
26+
-CA tests/tls/ca.crt \
27+
-CAkey tests/tls/ca.key \
28+
-CAserial tests/tls/ca.txt \
29+
-CAcreateserial \
30+
-days 365 \
31+
$opts \
32+
-out $certfile
33+
}
34+
35+
mkdir -p tests/tls
36+
[ -f tests/tls/ca.key ] || openssl genrsa -out tests/tls/ca.key 4096
37+
openssl req \
38+
-x509 -new -nodes -sha256 \
39+
-key tests/tls/ca.key \
40+
-days 3650 \
41+
-subj '/O=Redis Test/CN=Certificate Authority' \
42+
-out tests/tls/ca.crt
43+
44+
cat > tests/tls/openssl.cnf <<_END_
45+
[ server_cert ]
46+
keyUsage = digitalSignature, keyEncipherment
47+
nsCertType = server
48+
49+
[ client_cert ]
50+
keyUsage = digitalSignature, keyEncipherment
51+
nsCertType = client
52+
_END_
53+
54+
generate_cert server "Server-only" "-extfile tests/tls/openssl.cnf -extensions server_cert"
55+
generate_cert client "Client-only" "-extfile tests/tls/openssl.cnf -extensions client_cert"
56+
generate_cert redis "Generic-cert"
57+
58+
[ -f tests/tls/redis.dh ] || openssl dhparam -out tests/tls/redis.dh 2048

tests/include.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,21 @@ def addTLSArgs(benchmark_specs, env):
8383
if env.useTLS:
8484
benchmark_specs['args'].append('--tls')
8585
benchmark_specs['args'].append('--cert={}'.format(TLS_CERT))
86-
benchmark_specs['args'].append('--key={}'.format(TLS_KEY))
8786
benchmark_specs['args'].append('--cacert={}'.format(TLS_CACERT))
87+
if TLS_KEY != "":
88+
benchmark_specs['args'].append('--key={}'.format(TLS_KEY))
89+
else:
90+
benchmark_specs['args'].append('--tls-skip-verify')
91+
8892

8993

90-
def get_default_memtier_config():
94+
def get_default_memtier_config(threads=10, clients=5, requests=1000):
9195
config = {
9296
"memtier_benchmark": {
9397
"binary": MEMTIER_BINARY,
94-
"threads": 10,
95-
"clients": 5,
96-
"requests": 1000
98+
"threads": threads,
99+
"clients": clients,
100+
"requests": requests
97101
},
98102
}
99103
return config
@@ -106,3 +110,4 @@ def ensure_clean_benchmark_folder(dirname):
106110
if os.path.exists(dirname):
107111
os.removedirs(dirname)
108112
os.makedirs(dirname)
113+

tests/run_tests.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
3+
[[ $VERBOSE == 1 ]] && set -x
4+
5+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
6+
ROOT=$(cd $HERE/.. && pwd)
7+
8+
#----------------------------------------------------------------------------------------------
9+
10+
help() {
11+
cat <<-END
12+
Run flow tests.
13+
14+
[ARGVARS...] run_tests.sh [--help|help]
15+
16+
Argument variables:
17+
18+
OSS_STANDALONE=0|1 General tests on standalone Redis (default)
19+
OSS_CLUSTER=0|1 General tests on Redis OSS Cluster
20+
TLS=0|1 Run tests with TLS enabled
21+
SHARDS=n Number of shards (default: 3)
22+
23+
REDIS_SERVER=path Location of redis-server
24+
VERBOSE=1 Print commands
25+
26+
END
27+
}
28+
29+
#----------------------------------------------------------------------------------------------
30+
31+
run_tests() {
32+
local title="$1"
33+
if [[ -n $title ]]; then
34+
printf "Running $title:\n\n"
35+
fi
36+
37+
if [[ $VERBOSE == 1 ]]; then
38+
echo "RLTest configuration:"
39+
echo "$RLTEST_ARGS"
40+
fi
41+
42+
cd $ROOT/tests
43+
44+
local E=0
45+
{
46+
$OP python3 -m RLTest $RLTEST_ARGS
47+
((E |= $?))
48+
} || true
49+
50+
return $E
51+
}
52+
53+
#----------------------------------------------------------------------------------------------
54+
55+
[[ $1 == --help || $1 == help ]] && {
56+
help
57+
exit 0
58+
}
59+
60+
#----------------------------------------------------------------------------------------------
61+
62+
OSS_STANDALONE=${OSS_STANDALONE:-1}
63+
OSS_CLUSTER=${OSS_CLUSTER:-0}
64+
SHARDS=${SHARDS:-3}
65+
66+
TLS_KEY=$ROOT/tests/tls/redis.key
67+
TLS_CERT=$ROOT/tests/tls/redis.crt
68+
TLS_CACERT=$ROOT/tests/tls/ca.crt
69+
REDIS_SERVER=${REDIS_SERVER:-redis-server}
70+
MEMTIER_BINARY=$ROOT/memtier_benchmark
71+
72+
RLTEST_ARGS=" --oss-redis-path $REDIS_SERVER"
73+
[[ $VERBOSE == 1 ]] && RLTEST_ARGS+=" -v"
74+
[[ $TLS == 1 ]] && RLTEST_ARGS+=" --tls-cert-file $TLS_CERT --tls-key-file $TLS_KEY --tls-ca-cert-file $TLS_CACERT --tls"
75+
76+
cd $ROOT/tests
77+
78+
E=0
79+
[[ $OSS_STANDALONE == 1 ]] && {
80+
(TLS_KEY=$TLS_KEY TLS_CERT=$TLS_CERT TLS_CACERT=$TLS_CACERT MEMTIER_BINARY=$MEMTIER_BINARY RLTEST_ARGS="${RLTEST_ARGS}" run_tests "tests on OSS standalone")
81+
((E |= $?))
82+
} || true
83+
84+
[[ $OSS_CLUSTER == 1 ]] && {
85+
(TLS_KEY=$TLS_KEY TLS_CERT=$TLS_CERT TLS_CACERT=$TLS_CACERT MEMTIER_BINARY=$MEMTIER_BINARY RLTEST_ARGS="${RLTEST_ARGS} --env oss-cluster --shards-count $SHARDS" run_tests "tests on OSS cluster")
86+
((E |= $?))
87+
} || true
88+
89+
exit $E

0 commit comments

Comments
 (0)