Skip to content

Commit 6f0735c

Browse files
authored
Add timeout to client registration (#444)
1 parent fd1e395 commit 6f0735c

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

docker/integtest/1-register-client.sh

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ mkdir -p "${out_dir}"
77
# shellcheck disable=SC1090
88
. "${scriptdir}/utils.sh"
99

10+
readonly polling_interval_seconds=2
11+
readonly max_retries=150
12+
13+
wait_for_client() {
14+
local client="$1"
15+
local i
16+
17+
for i in $(seq 1 "${max_retries}"); do
18+
if curl -fs -u "${REGISTRATION_CREDENTIALS}" "http://nginx:8888/api/email/register/developer${client}.lokole.ca" | tee "${out_dir}/register${client}.json"; then
19+
log "Client ${client} is registered"
20+
return
21+
fi
22+
log "Waiting for client ${client} registration (${i}/${max_retries})"
23+
sleep "${polling_interval_seconds}"
24+
done
25+
26+
exit 1
27+
}
28+
1029
# workflow 3: register a new client called "developer"
1130
# normally this endpoint would be called during a new lokole device setup
1231
curl -fs \
@@ -15,10 +34,7 @@ curl -fs \
1534
-d '{"domain":"developer1.lokole.ca"}' \
1635
"http://nginx:8888/api/email/register/"
1736

18-
while ! curl -fs -u "${REGISTRATION_CREDENTIALS}" "http://nginx:8888/api/email/register/developer1.lokole.ca" | tee "${out_dir}/register1.json"; do
19-
log "Waiting for client 1 registration"
20-
sleep 1s
21-
done
37+
wait_for_client 1
2238

2339
# registering a client with bad credentials should fail
2440
if curl -fs \
@@ -35,10 +51,7 @@ curl -fs \
3551
-d '{"domain":"developer2.lokole.ca"}' \
3652
"http://nginx:8888/api/email/register/"
3753

38-
while ! curl -fs -u "${REGISTRATION_CREDENTIALS}" "http://nginx:8888/api/email/register/developer2.lokole.ca" | tee "${out_dir}/register2.json"; do
39-
log "Waiting for client 2 registration"
40-
sleep 1s
41-
done
54+
wait_for_client 2
4255

4356
# after creating a client, creating the same one again should fail but we should be able to delete it
4457
curl -fs \
@@ -47,10 +60,7 @@ curl -fs \
4760
-d '{"domain":"developer3.lokole.ca"}' \
4861
"http://nginx:8888/api/email/register/"
4962

50-
while ! curl -fs -u "${REGISTRATION_CREDENTIALS}" "http://nginx:8888/api/email/register/developer3.lokole.ca"; do
51-
log "Waiting for client 3 registration"
52-
sleep 1s
53-
done
63+
wait_for_client 3
5464

5565
if curl -fs \
5666
-H "Content-Type: application/json" \

0 commit comments

Comments
 (0)