Skip to content

Commit dd202a7

Browse files
committed
test: Add GHA job testing learn-ocaml-client against other server(s)
* Adapt ./tests/runtests.sh so it recognizes USE_CLIENT_IMAGE=true * Update .github/workflows/build-and-test.yml accordingly so learn-ocaml-client runs against each ${{ matrix.server_image }}
1 parent 431113f commit dd202a7

File tree

2 files changed

+86
-8
lines changed

2 files changed

+86
-8
lines changed

.github/workflows/build-and-test.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,33 @@ jobs:
2727
- name: Run learn-ocaml build on learn-ocaml-corpus
2828
run: "cd tests && bash -c ./runtests.sh"
2929

30+
client_using_other_server:
31+
name: Build learn-ocaml-client and run quick tests
32+
runs-on: ubuntu-latest
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
server_image:
37+
- 'ocamlsf/learn-ocaml:0.12'
38+
- 'learn-ocaml' # use learn-ocaml image built from master
39+
env:
40+
USE_CLIENT_IMAGE: 'true'
41+
steps:
42+
- name: Check out the repo
43+
uses: actions/checkout@v2
44+
- name: Build Docker images
45+
run: "make docker-images"
46+
# unneeded
47+
# - name: Run learn-ocaml build on demo-repository
48+
# run: "docker run --rm -v $(pwd)/demo-repository:/repository learn-ocaml -- build"
49+
- name: Pull server_image
50+
if: ${{ matrix.server_image != 'learn-ocaml' }}
51+
run: "docker pull ${{ matrix.server_image }} && docker tag ${{ matrix.server_image }} learn-ocaml"
52+
- name: Print images metadata
53+
run: "docker inspect -f '{{json .Config.Labels}}' learn-ocaml-client learn-ocaml | jq"
54+
- name: Run learn-ocaml build on learn-ocaml-corpus
55+
run: "cd tests && bash -c ./runtests.sh"
56+
3057
build_extra_tests:
3158
name: Run dockerized tests
3259
runs-on: ubuntu-latest

tests/runtests.sh

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@
22

33
let count=0
44

5-
# If the first argument is "set", the script will replace all the expected
5+
# If the first argument is "set", the script will replace all the expected
66
# answers by the response of the server. It is useful when you need to
77
# initialize a set of tests.
88

9+
# If the environment variable $USE_CLIENT_IMAGE is set to "true", then
10+
# the script will use both images learn-ocaml and learn-ocaml-client,
11+
# instead of the mere learn-ocaml image. It is useful for testing
12+
# cross-version compatibility.
13+
914
SETTER=0
1015
if [ "$1" == "set" ]; then SETTER=1; fi
1116

17+
use_client_image () {
18+
if [ "$USE_CLIENT_IMAGE" = "true" ]; then
19+
return 0
20+
else
21+
return 1
22+
fi
23+
}
24+
1225
# print in green $1
1326
green () {
1427
echo -e "\e[32m$1\e[0m"
@@ -19,6 +32,12 @@ red () {
1932
echo -e "\e[31m$1\e[0m"
2033
}
2134

35+
if use_client_image; then
36+
green "Running tests with BOTH images (learn-ocaml, learn-ocaml-client)"
37+
else
38+
green "Running tests with single image learn-ocaml"
39+
fi
40+
2241
# run a server in a docker container
2342
run_server () {
2443
SYNC="$(pwd)"/"$dir"/sync
@@ -28,7 +47,7 @@ run_server () {
2847
chmod o+w "$dir"/sync
2948

3049
# Run the server in background
31-
SERVERID=$(docker run --entrypoint '' -d \
50+
SERVERID=$(docker run --entrypoint '' -d -p 8080:8080 \
3251
-v "$(pwd)"/"$dir":/home/learn-ocaml/actual \
3352
-v "$SYNC":/sync -v "$REPO":/repository \
3453
learn-ocaml /bin/sh \
@@ -50,6 +69,25 @@ learn-ocaml --sync-dir=/sync --repo=/repository build serve")
5069
docker rm "$SERVERID" > /dev/null
5170
exit 1
5271
fi
72+
73+
if use_client_image; then
74+
# Run the client in background
75+
CLIENTID=$(docker run --entrypoint '' -d -it --name=client \
76+
-add-host host.docker.internal:host-gateway \
77+
-v "$(pwd)"/"$dir":/home/learn-ocaml/actual \
78+
learn-ocaml-client /bin/sh)
79+
80+
# Wait for the client to be initialized
81+
sleep 2
82+
if [ "$(docker ps -q -f name=client)" == "" ]; then
83+
red "PROBLEM, client is not running.\n"
84+
85+
red "LOGS:"
86+
docker logs "$CLIENTID"
87+
docker rm "$CLIENTID" > /dev/null
88+
exit 1
89+
fi
90+
fi
5391
}
5492

5593
clean () {
@@ -58,6 +96,11 @@ clean () {
5896

5997
docker kill "$SERVERID" > /dev/null
6098
docker rm "$SERVERID" > /dev/null
99+
100+
if use_client_image; then
101+
docker kill "$CLIENTID" > /dev/null
102+
docker rm "$CLIENTID" > /dev/null
103+
fi
61104
}
62105

63106
clean_fail () {
@@ -69,9 +112,13 @@ handle_file () {
69112
subdir="$1"
70113
tosend="$(basename "$2")"
71114
# Grade file
72-
docker exec -i "$SERVERID" \
73-
learn-ocaml-client grade --json --id="$subdir" \
74-
/home/learn-ocaml/actual/"$subdir"/"$tosend" > res.json 2> stderr.txt
115+
args=(learn-ocaml-client grade --json --id="$subdir"
116+
/home/learn-ocaml/actual/"$subdir"/"$tosend")
117+
if use_client_image; then
118+
docker exec -i "$CLIENTID" "${args[@]}" > res.json 2> stderr.txt
119+
else
120+
docker exec -i "$SERVERID" "${args[@]}" > res.json 2> stderr.txt
121+
fi
75122
if [ $? -ne 0 ]; then
76123
red "NOT OK: $dir/$tosend"
77124
cat stderr.txt
@@ -102,9 +149,13 @@ handle_subdir () {
102149
subdir="$(basename "$1")"
103150
pushd "$1" >/dev/null
104151

105-
#init config
106-
docker exec -i "$SERVERID" \
107-
learn-ocaml-client init --server=http://localhost:8080 --token="$token"
152+
# init config
153+
args=(learn-ocaml-client init --token="$token")
154+
if use_client_image; then
155+
docker exec -i "$CLIENTID" "${args[@]}" --server="http://host.docker.internal:8080"
156+
else
157+
docker exec -i "$SERVERID" "${args[@]}" --server="http://localhost:8080"
158+
fi
108159
# For each solution
109160
for tosend in $(find . -name "*.ml" -type f -printf "%f\n")
110161
do

0 commit comments

Comments
 (0)