Skip to content

Commit 84c837c

Browse files
committed
Moved testing logic out of github actions
1 parent 659b248 commit 84c837c

File tree

6 files changed

+270
-59
lines changed

6 files changed

+270
-59
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,21 @@ jobs:
1515
sudo apt-get -qq update
1616
sudo apt-get install autoconf automake pkg-config libevent-dev libpcre3-dev libssl-dev
1717
- name: Build
18-
run: autoreconf -ivf && ./configure && make
18+
run: autoreconf -ivf && ./configure && make -j
1919
- name: Setup Python
20-
uses: actions/setup-python@v1
20+
uses: actions/setup-python@v2
2121
with:
2222
python-version: '3.6'
23+
architecture: x64
2324

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 }}-
3325
- name: Install Python dependencies
34-
run: pip install -r tests/test_requirements.txt
26+
run: pip install -r ./tests/test_requirements.txt
3527

3628
- name: Cache Redis
3729
id: cache-redis
3830
uses: actions/cache@v1
3931
with:
40-
path: /home/runner/work/memtier_benchmark/memtier_benchmark/redis
32+
path: /home/runner/work/redis
4133
key: ${{ runner.os }}-redis
4234

4335
- name: Check out Redis
@@ -52,61 +44,41 @@ jobs:
5244
if: steps.cache-redis.outputs.cache-hit != 'true'
5345
run: |
5446
cd redis
55-
make BUILD_TLS=yes
56-
./utils/gen-test-certs.sh
47+
make BUILD_TLS=yes -j
5748
./src/redis-server --version
5849
50+
- name: Generate TLS test certificates
51+
if: matrix.platform == 'ubuntu-latest'
52+
run: |
53+
./tests/gen-test-certs.sh
54+
5955
- name: Test OSS TCP
56+
timeout-minutes: 10
6057
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 ..
58+
REDIS_SERVER=../redis/src/redis-server \
59+
./tests/run_tests.sh
6760
6861
- name: Test OSS TCP TLS
6962
if: matrix.platform == 'ubuntu-latest'
63+
timeout-minutes: 10
7064
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 ..
65+
TLS=1 REDIS_SERVER=../redis/src/redis-server \
66+
./tests/run_tests.sh
8467
8568
- name: Test OSS-CLUSTER TCP
69+
timeout-minutes: 10
8670
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 ..
71+
OSS_STANDALONE=0 OSS_CLUSTER=1 \
72+
REDIS_SERVER=../redis/src/redis-server \
73+
./tests/run_tests.sh
9374
9475
- name: Test OSS-CLUSTER TCP TLS
76+
timeout-minutes: 10
9577
if: matrix.platform == 'ubuntu-latest'
9678
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 ..
79+
OSS_STANDALONE=0 OSS_CLUSTER=1 TLS=1 \
80+
REDIS_SERVER=../redis/src/redis-server \
81+
./tests/run_tests.sh
11082
11183
build-macos:
11284
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__

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

0 commit comments

Comments
 (0)