forked from cescoffier/reactive-coffeeshop-demo
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ci-test.sh
executable file
·60 lines (49 loc) · 1.71 KB
/
ci-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
set -ex
# First argument customizes service port (default, 8080)
SERVICE_PORT=${1:-8080}
# Second argument contains coffeeshop namespace (default, coffee)
NAMESPACE=${2:-"coffee"}
# Test POSTing an order
response=`curl -s -d"{\"name\":\"Travis\",\"product\":\"frappuccino\"}" -H "Content-Type: application/json" http://localhost:${SERVICE_PORT}/services/messaging`
responseRegex='orderId" *: *"[a-z0-9-]+"'
if [[ "$response" =~ $responseRegex ]]; then
echo "Order ID assigned"
else
echo "Order ID not found"
false
fi
# Test order completion. Wait for a response in the stream
# (it should only take around 5 seconds for barista-kafka to respond, but may
# take much longer in a CI environment)
# It may also take longer for the initial response if Keda has scaled the kafka
# barista to zero.
timeout=180
# Stream output from the queue to a temporary file
echo "" > tmp.out
curl -s --no-buffer http://localhost:${SERVICE_PORT}/services/queue > tmp.out &
curlpid=$!
# Poll the temporary file, looking for a line containing the expected response
set +x
for i in `seq 0 ${timeout}`; do
eventStream=`grep "READY" tmp.out` && break || sleep 1
if [ $(($i % 5)) -eq 0 ]; then
# Display periodic progress while we wait
echo "Waiting for order completion ($i seconds)"
fi
if [ $(($i % 10)) -eq 0 ]; then
# Occasionally show the status of pods if we're waiting a long time
kubectl get pods -n $NAMESPACE &
fi
done
set -x
# Kill the stream
kill $curlpid
# Check that the response contains the expected output
responseRegex='"state" *: *"READY"'
if [[ "$eventStream" =~ $responseRegex ]]; then
echo "Order was successfully processed after $i seconds"
else
echo "Order completion not detected"
false
fi