Skip to content

Commit 3bd747c

Browse files
committed
tests: use dedicated redis port in integration
1 parent fcb45e5 commit 3bd747c

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ jobs:
4141
run: sudo apt-get install valgrind
4242
- name: Test
4343
run: ./test.sh
44-
env:
45-
USE_VALGRIND: "0"
4644

4745
coverage:
4846
name: Generate and upload coverage

tests/helper.sh

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
set -eu
44

5-
LOG_FILE=""
5+
LOG_FILE="${LOG_FILE:-}"
6+
REDIS_PID=""
7+
REDIS_PORT="${REDIS_PORT:-}"
68
function setup() {
79
mkdir -p build
810
cd build
@@ -41,25 +43,57 @@ function start_redis() {
4143
LIB_PATH="./build/libredis-roaring.so"
4244
fi
4345

44-
local REDIS_COMMAND="./deps/redis/src/redis-server --loglevel warning --loadmodule $LIB_PATH"
46+
if [ "$REDIS_PORT" == "" ]; then
47+
for port in 6379 6380 6381 6382 6383; do
48+
if ./deps/redis/src/redis-cli -p "$port" PING >/dev/null 2>&1; then
49+
continue
50+
fi
51+
REDIS_PORT="$port"
52+
break
53+
done
54+
fi
55+
56+
if [ "$REDIS_PORT" == "" ]; then
57+
echo "No available Redis port found for tests" >&2
58+
exit 1
59+
fi
60+
export REDIS_PORT
61+
62+
local REDIS_COMMAND="./deps/redis/src/redis-server --loglevel warning --loadmodule $LIB_PATH --port $REDIS_PORT"
4563
local VALGRIND_COMMAND="valgrind --leak-check=yes --show-leak-kinds=definite,indirect --suppressions=./deps/redis/src/valgrind.sup --error-exitcode=1 --log-file=$LOG_FILE"
4664
local AOF_OPTION="--appendonly $USE_AOF"
4765
if [ "$USE_VALGRIND" == "no" ]; then
4866
VALGRIND_COMMAND=""
4967
fi
5068

5169
eval "$VALGRIND_COMMAND" "$REDIS_COMMAND" "$AOF_OPTION" &
70+
REDIS_PID=$!
5271

53-
while [ "$(./deps/redis/src/redis-cli PING 2>/dev/null)" != "PONG" ]; do
72+
while [ "$(./deps/redis/src/redis-cli -p "$REDIS_PORT" PING 2>/dev/null)" != "PONG" ]; do
5473
sleep 0.1
5574
done
5675
}
5776

5877
function stop_redis() {
59-
pkill -f redis || true
60-
while [ $(ps aux | grep redis | grep -v grep | wc -l) -ne 0 ]; do
61-
sleep 0.1
62-
done
78+
if [ "$REDIS_PORT" != "" ] && [ "$(./deps/redis/src/redis-cli -p "$REDIS_PORT" PING 2>/dev/null)" == "PONG" ]; then
79+
./deps/redis/src/redis-cli -p "$REDIS_PORT" shutdown nosave >/dev/null 2>&1 || true
80+
fi
81+
82+
if [ "$REDIS_PID" != "" ]; then
83+
if kill -0 "$REDIS_PID" 2>/dev/null; then
84+
kill "$REDIS_PID" 2>/dev/null || true
85+
local tries=0
86+
while kill -0 "$REDIS_PID" 2>/dev/null; do
87+
sleep 0.1
88+
tries=$((tries + 1))
89+
if [ "$tries" -ge 300 ]; then
90+
break
91+
fi
92+
done
93+
fi
94+
REDIS_PID=""
95+
fi
96+
6397
sleep 2
6498
if [ "$LOG_FILE" != "" ]; then
6599
cat "$LOG_FILE"
@@ -72,15 +106,15 @@ function stop_redis() {
72106

73107
function rcall() {
74108
local cmd="$1"
75-
echo "$cmd" | ./deps/redis/src/redis-cli >/dev/null
109+
echo "$cmd" | ./deps/redis/src/redis-cli -p "$REDIS_PORT" >/dev/null
76110
}
77111

78112
function rcall_assert() {
79113
local cmd="$1"
80114
local expected="$(echo -e "$2")"
81115
local description="${3:-Redis command}"
82116

83-
local result=$(echo "$cmd" | ./deps/redis/src/redis-cli)
117+
local result=$(echo "$cmd" | ./deps/redis/src/redis-cli -p "$REDIS_PORT")
84118

85119
if [ "$result" == "$expected" ]; then
86120
echo -e "\x1b[32m✓\x1b[0m $description"

tests/integration_2.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -eu
77
function test_load() {
88
print_test_header "test_load"
99

10-
FOUND=$(echo "KEYS *" | ./deps/redis/src/redis-cli)
10+
FOUND=$(echo "KEYS *" | ./deps/redis/src/redis-cli -p "$REDIS_PORT")
1111
EXPECTED="test_"
1212
[[ "$FOUND" =~ .*"$EXPECTED".* ]]
1313
}

0 commit comments

Comments
 (0)