Skip to content

Commit 2510577

Browse files
committed
Improve portability of test script and add it to CI
1 parent f9e90f3 commit 2510577

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ jobs:
5656
- name: Test with pytest
5757
run: pytest --cov=src --cov-report=lcov
5858

59+
- name: Check quickstart, including installation
60+
run: ./docs/source/quickstart/test_quickstart_example.sh
61+
5962
- name: Upload code coverage
6063
uses: actions/upload-artifact@v4
6164
with:
@@ -97,6 +100,10 @@ jobs:
97100
if: success() || failure()
98101
run: pytest --cov=src --cov-report=lcov
99102

103+
- name: Check quickstart, including installation
104+
if: success() || failure()
105+
run: ./docs/source/quickstart/test_quickstart_example.sh
106+
100107
coverage:
101108
runs-on: ubuntu-latest
102109
needs: [base_coverage, test]
Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
1-
set -e
2-
1+
# cd to this directory
2+
cd "${BASH_SOURCE%/*}/"
3+
rm -rf .venv
4+
# Override the virtual environment so we use the package
5+
# from this repo, not from pypi
6+
python -m venv .venv
7+
source .venv/bin/activate
8+
pip install ../../..
39
# Run the quickstart code in the background
4-
bash ./quickstart_example.sh 2>&1 &
10+
bash "quickstart_example.sh" 2>&1 &
511
quickstart_example_pid=$!
612
echo "Spawned example with PID $quickstart_example_pid"
713

14+
function killserver {
15+
# Stop the server that we spawned.
16+
children=$(ps -o pid= --ppid "$quickstart_example_pid")
17+
kill $children
18+
echo "Killed spawned processes: $children"
19+
20+
wait
21+
}
22+
trap killserver EXIT
23+
824
# Wait for it to respond
925
# Loop until the command is successful or the maximum number of attempts is reached
1026
ret=7
1127
attempt_num=0
12-
while [[ $ret == 7 ]] && [ $attempt_num -le 50 ]; do
28+
while [[ $ret == 7 ]]; do # && [ $attempt_num -le 50 ]
1329
# Execute the command
1430
ret=0
1531
curl -sf -m 10 http://localhost:5000/counter/counter || ret=$?
@@ -29,22 +45,17 @@ while [[ $ret == 7 ]] && [ $attempt_num -le 50 ]; do
2945
done
3046
echo "Final return value $ret on attempt $attempt_num"
3147

32-
# Check the Python client code
33-
echo "Running Python client code"
34-
(. .venv/bin/activate && python counter_client.py)
35-
36-
37-
# Get the spawned server's PID
38-
children=$(ps -o pid= --ppid "$quickstart_example_pid")
39-
kill $children
40-
echo "Killed spawned processes: $children"
41-
42-
wait
43-
4448
if [[ $ret == 0 ]]; then
4549
echo "Success"
46-
exit 0
4750
else
4851
echo "Curl returned $ret, likely something went wrong."
4952
exit -1
50-
fi
53+
fi
54+
55+
# Check the Python client code
56+
echo "Running Python client code"
57+
(source .venv/bin/activate && python counter_client.py)
58+
if [[ $? != 0 ]]; then
59+
echo "Python client code did not run OK."
60+
exit -1
61+
fi

0 commit comments

Comments
 (0)