Skip to content

Commit 3301c84

Browse files
committed
ci: Exercise the right discipline to restart docker containers
One does not simply restart a docker container. But when you do, SpacetimeDB also restarts.
1 parent 31915b2 commit 3301c84

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ jobs:
1616
- name: Start containers
1717
run: docker compose up -d
1818
- name: Run smoketests
19-
# TODO: Fix flaky tests https://github.com/clockworklabs/SpacetimeDB/issues/630
2019
run: test/run-smoke-tests.sh --parallel -x bitcraftmini-pretest zz_docker-restart-module zz_docker-restart-repeating-reducer zz_docker-restart-sql
20+
# These cannot run in parallel, even though the script tries to handle it
21+
- name: Run restarting smoketests
22+
run: test/run-smoke-tests.sh zz_docker-restart-module zz_docker-restart-repeating-reducer zz_docker-restart-sql
2123
- name: Stop containers
2224
if: always()
2325
run: docker compose down

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ services:
2828
# Tracy
2929
- "8086:8086"
3030
entrypoint: cargo watch -i flamegraphs -i log.conf --why -C crates/standalone -x 'run start'
31+
healthcheck:
32+
test: curl -f http://localhost/database/ping || exit 1
3133
privileged: true
3234
environment:
3335
SPACETIMEDB_FLAMEGRAPH_PATH: ../../../../flamegraphs/flamegraph.folded

test/lib.include

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,45 @@ fsed() {
7474
}
7575

7676
restart_docker() {
77-
docker-compose stop node
78-
docker-compose start node
79-
sleep 10
77+
# Behold!
78+
#
79+
# You thought stop/start restarts? How wrong. Restart restarts.
80+
docker compose restart
81+
# The suspense!
82+
#
83+
# Wait until compose believes the health probe succeeds.
84+
#
85+
# The container may decide to recompile, or grab a coffee at crates.io, or
86+
# whatever. In any case, restart doesn't mean the server is up yet.
87+
docker compose up --no-recreate --detach --wait-timeout 60
88+
# Belts and suspenders!
89+
#
90+
# The health probe runs inside the container, but that doesn't mean we can
91+
# reach it from outside. Ping until we get through.
92+
ping
93+
}
94+
95+
ping() {
96+
local retries=5
97+
local success=0
98+
while true
99+
do
100+
curl -sf http://127.0.0.1:3000/database/ping && { success=1; break; } || echo "Server down"
101+
retries=$((retries - 1))
102+
if [ $retries -gt 0 ]
103+
then
104+
sleep 5
105+
else
106+
break
107+
fi
108+
done
109+
if [ $success -lt 1 ]
110+
then
111+
echo "Server at 127.0.0.1:3000 not responding"
112+
exit 127
113+
else
114+
echo "Server up after $((5 - retries)) retries"
115+
fi
80116
}
81117

82118
# vim: noexpandtab tabstop=4 shiftwidth=4

0 commit comments

Comments
 (0)