Skip to content

Commit 29a1b7a

Browse files
committed
fix(ci): wait for redis cluster nodes to accept connections before creating the cluster
1 parent 5fcc5bd commit 29a1b7a

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

.github/workflows/tests.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,27 @@ jobs:
110110
sudo apt update
111111
sudo apt-get install -y --fix-missing redis-server
112112
sudo service redis-server stop
113-
redis-server --daemonize yes --port 7000 --appendonly yes --cluster-enabled yes --cluster-config-file nodes-7000.conf
114-
redis-server --daemonize yes --port 7001 --appendonly yes --cluster-enabled yes --cluster-config-file nodes-7001.conf
115-
redis-server --daemonize yes --port 7002 --appendonly yes --cluster-enabled yes --cluster-config-file nodes-7002.conf
113+
114+
for port in 7000 7001 7002; do
115+
redis-server --daemonize yes --port "$port" --appendonly yes --cluster-enabled yes --cluster-config-file "nodes-$port.conf"
116+
done
117+
118+
# --daemonize returns as soon as the parent forks, before the node
119+
# accepts connections, so creating the cluster straight away races
120+
# the last node into a refused connection. Wait for every node to
121+
# answer PING first.
122+
for port in 7000 7001 7002; do
123+
for attempt in $(seq 30); do
124+
if [ "$(redis-cli -p "$port" ping 2>/dev/null)" = "PONG" ]; then
125+
continue 2
126+
fi
127+
sleep 1
128+
done
129+
130+
echo "Redis node on port $port never started accepting connections."
131+
exit 1
132+
done
133+
116134
redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 --cluster-replicas 0 --cluster-yes
117135
118136
- name: Check Redis Cluster is ready

0 commit comments

Comments
 (0)