summaryrefslogtreecommitdiff
path: root/test/end-to-end/serve-service
diff options
context:
space:
mode:
authorAlberto Sartori <alberto.sartori@huawei.com>2023-10-20 17:43:45 +0200
committerAlberto Sartori <alberto.sartori@huawei.com>2023-11-15 20:19:18 +0100
commit767716edc1a2aa930dd142a42a2d664addf151c1 (patch)
tree43288a7cb0372cb88fba1a8b5e99cc31bf7d6a00 /test/end-to-end/serve-service
parent4e70813985c2487f3602193cbb0cc76ce345602b (diff)
downloadjustbuild-767716edc1a2aa930dd142a42a2d664addf151c1.tar.gz
just-serve: add end-to-end tests
serve_target_remote_build.sh should be updated once just-serve can orchestrate the remote build
Diffstat (limited to 'test/end-to-end/serve-service')
-rw-r--r--test/end-to-end/serve-service/TARGETS39
-rw-r--r--test/end-to-end/serve-service/serve_export_deps.sh159
-rw-r--r--test/end-to-end/serve-service/serve_start_execute.sh79
-rw-r--r--test/end-to-end/serve-service/serve_target_cache_hit.sh153
-rw-r--r--test/end-to-end/serve-service/serve_target_remote_build.sh63
5 files changed, 493 insertions, 0 deletions
diff --git a/test/end-to-end/serve-service/TARGETS b/test/end-to-end/serve-service/TARGETS
new file mode 100644
index 00000000..b53cf0e1
--- /dev/null
+++ b/test/end-to-end/serve-service/TARGETS
@@ -0,0 +1,39 @@
+{ "serve-target-remote-build":
+ { "type": ["end-to-end", "with serve"]
+ , "name": ["serve-target-remote-build"]
+ , "test": ["serve_target_remote_build.sh"]
+ , "deps":
+ [["end-to-end", "tool-under-test"], ["end-to-end", "mr-tool-under-test"]]
+ , "repos": [["end-to-end/target-cache/data", "greetlib"]]
+ }
+, "serve-target-cache-hit":
+ { "type": ["end-to-end", "with serve"]
+ , "name": ["serve-target-cache-hit"]
+ , "test": ["serve_target_cache_hit.sh"]
+ , "deps":
+ [["end-to-end", "mr-tool-under-test"], ["end-to-end", "tool-under-test"]]
+ }
+, "serve-start-execute":
+ { "type": ["@", "rules", "shell/test", "script"]
+ , "name": ["serve-start-execute"]
+ , "test": ["serve_start_execute.sh"]
+ , "deps": [["end-to-end", "tool-under-test"]]
+ }
+, "serve-export-deps":
+ { "type": ["end-to-end", "with serve"]
+ , "name": ["serve-export-deps"]
+ , "test": ["serve_export_deps.sh"]
+ , "deps":
+ [["end-to-end", "mr-tool-under-test"], ["end-to-end", "tool-under-test"]]
+ }
+, "TESTS":
+ { "type": "install"
+ , "tainted": ["test"]
+ , "deps":
+ [ "serve-target-remote-build"
+ , "serve-target-cache-hit"
+ , "serve-start-execute"
+ , "serve-export-deps"
+ ]
+ }
+}
diff --git a/test/end-to-end/serve-service/serve_export_deps.sh b/test/end-to-end/serve-service/serve_export_deps.sh
new file mode 100644
index 00000000..6c21734d
--- /dev/null
+++ b/test/end-to-end/serve-service/serve_export_deps.sh
@@ -0,0 +1,159 @@
+#!/bin/sh
+# Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+###########################################################################
+#
+# We test that we are able to compile an export target, which depends on an
+# absent one.
+#
+###########################################################################
+
+set -eu
+env
+readonly JUST="${PWD}/bin/tool-under-test"
+readonly JUST_MR="${PWD}/bin/mr-tool-under-test"
+
+readonly LBR="${TEST_TMPDIR}/local-build-root"
+
+readonly LOCAL_DIR="${TEST_TMPDIR}/local"
+readonly ABSENT_DIR="${TEST_TMPDIR}/absent"
+
+# Set up sample repository
+readonly GENERATOR="${TEST_TMPDIR}/generate.sh"
+readonly GEN_DIR="{TEST_TMPDIR}/gen-dir"
+cat > "${GENERATOR}" <<EOF
+#!/bin/sh
+
+cat > TARGETS <<ENDTARGETS
+{ "main-internal":
+ { "type": "generic"
+ , "cmds": ["echo hello from just-serve > out.txt"]
+ , "outs": ["out.txt"]
+ }
+, "main":
+ {"type": "export", "target": "main-internal", "flexible_config": ["ENV"]}
+}
+ENDTARGETS
+EOF
+chmod 755 "${GENERATOR}"
+mkdir -p "${GEN_DIR}"
+( cd "${GEN_DIR}"
+ git init
+ git config user.email "nobody@example.org"
+ git config user.name "Nobody"
+ "${GENERATOR}"
+ git add .
+ git commit -m "first commit"
+)
+readonly TREE_ID=$(cd "${GEN_DIR}" && git log -n 1 --format="%T")
+
+# fill the target cache that will be used by just serve
+mkdir -p ${LOCAL_DIR}
+( cd ${LOCAL_DIR}
+touch ROOT
+cat > repos.json <<EOF
+{ "repositories":
+ { "":
+ { "repository":
+ { "type": "git tree"
+ , "id": "${TREE_ID}"
+ , "cmd": ["${GENERATOR}"]
+ }
+ }
+ }
+}
+EOF
+echo "local repos configuration:"
+cat repos.json
+
+CONF=$("${JUST_MR}" --norc --local-build-root "${SERVE_LBR}" setup)
+cat "${CONF}"
+"${JUST}" build --local-build-root "${SERVE_LBR}" -C "${CONF}" -r ${REMOTE_EXECUTION_ADDRESS} main
+)
+
+# Set up local repository
+readonly GENERATOR_LOCAL="${TEST_TMPDIR}/generate_local.sh"
+readonly GEN_DIR_LOCAL="{TEST_TMPDIR}/local-repo"
+cat > "${GENERATOR_LOCAL}" <<EOF
+#!/bin/sh
+
+cat > TARGETS <<EOFTARGETS
+{ "main-internal":
+ { "type": "generic"
+ , "cmds": ["cat out.txt > local.txt"]
+ , "outs": ["local.txt"]
+ , "deps" : [["@", "absent-dep", "", "main"]]
+ }
+, "main":
+ {"type": "export", "target": "main-internal", "flexible_config": ["ENV"]}
+}
+EOFTARGETS
+EOF
+
+chmod 755 "${GENERATOR_LOCAL}"
+mkdir -p "${GEN_DIR_LOCAL}"
+( cd "${GEN_DIR_LOCAL}"
+ git init
+ git config user.email "nobody@example.org"
+ git config user.name "Nobody"
+ "${GENERATOR_LOCAL}"
+ git add .
+ git commit -m "first commit"
+)
+readonly TREE_ID_LOCAL=$(cd "${GEN_DIR_LOCAL}" && git log -n 1 --format="%T")
+
+
+# test with the absent repository
+mkdir -p "${ABSENT_DIR}"
+( cd "${ABSENT_DIR}"
+touch ROOT
+cat > repos.json <<EOF
+{
+ "repositories":
+ { "local":
+ { "repository":
+ { "type": "git tree"
+ , "id": "${TREE_ID_LOCAL}"
+ , "cmd": ["${GENERATOR_LOCAL}"]
+ }
+ , "bindings" : {"absent-dep": "absent-dep"}
+ }
+ , "absent-dep":
+ { "repository":
+ { "type": "git tree"
+ , "id": "${TREE_ID}"
+ , "cmd": ["${GENERATOR}"]
+ , "pragma": {"absent": true}
+ }
+ }
+ }
+}
+EOF
+
+echo "absent repos configuration:"
+cat repos.json
+echo
+
+rm "${GENERATOR}"
+
+CONF=$("${JUST_MR}" --norc --local-build-root "${LBR}" setup --all)
+cat "${CONF}"
+echo
+
+# test that we can successfully compile using just serve
+"${JUST}" build --main local --local-build-root "${LBR}" -C "${CONF}" --remote-serve-address ${SERVE} -r ${REMOTE_EXECUTION_ADDRESS} main
+"${JUST}" build --main local --local-build-root "${LBR}" -C "${CONF}" --remote-serve-address ${SERVE} -r ${REMOTE_EXECUTION_ADDRESS} main
+)
diff --git a/test/end-to-end/serve-service/serve_start_execute.sh b/test/end-to-end/serve-service/serve_start_execute.sh
new file mode 100644
index 00000000..6cc0448f
--- /dev/null
+++ b/test/end-to-end/serve-service/serve_start_execute.sh
@@ -0,0 +1,79 @@
+#!/bin/sh
+# Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+###########################################################################
+#
+# By design, when a just-serve instance is created, if no remote-execution
+# endpoint is provided, the same process will act also as just-execute.
+#
+###########################################################################
+
+set -eu
+env
+readonly JUST="${PWD}/bin/tool-under-test"
+
+readonly LBR="${TEST_TMPDIR}/local-build-root"
+
+readonly INFOFILE="${PWD}/info.json"
+readonly PIDFILE="${PWD}/pid.txt"
+
+# test that, if no remote endpoint is passed to just-serve, it will spawn a
+# just-execute instance
+cat > .just-servec <<EOF
+{ "repositories": []
+, "remote service": {"info file": "${INFOFILE}", "pid file": "${PIDFILE}"}
+, "local build root": "${LBR}"
+}
+EOF
+echo "Serve service configuration:"
+cat .just-servec
+
+"${JUST}" serve .just-servec 2>&1 &
+
+for _ in `seq 1 10`
+do
+ if test -f "${INFOFILE}"
+ then
+ break
+ fi
+ sleep 1;
+done
+
+if ! test -f "${INFOFILE}"
+then
+ echo "Did not find ${INFOFILE}"
+ exit 1
+fi
+
+readonly PORT=$(jq '."port"' "${INFOFILE}")
+
+cleanup() {
+ kill $(cat "${PIDFILE}")
+}
+trap cleanup EXIT
+
+touch ROOT
+cat > TARGETS <<ENDTARGETS
+{ "":
+ { "type": "generic"
+ , "cmds": ["echo hello from just-serve-just-execute > out.txt"]
+ , "outs": ["out.txt"]
+ }
+}
+
+ENDTARGETS
+
+"${JUST}" install --local-build-root "${LBR}" -r localhost:${PORT} -o .
+grep 'just-serve-just-execute' out.txt
diff --git a/test/end-to-end/serve-service/serve_target_cache_hit.sh b/test/end-to-end/serve-service/serve_target_cache_hit.sh
new file mode 100644
index 00000000..7d6c118b
--- /dev/null
+++ b/test/end-to-end/serve-service/serve_target_cache_hit.sh
@@ -0,0 +1,153 @@
+#!/bin/sh
+# Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+###########################################################################
+#
+# In this script, we first fill the target cache of a running just-serve
+# instance by "locally" compiling the export target. Then, we check that
+# just-serve can, well, serve the requested absent target.
+#
+# The remote properties and dispatch file are only used to test that both
+# client and server shard the target cache entry in the same way
+#
+###########################################################################
+
+set -eu
+env
+readonly JUST="${PWD}/bin/tool-under-test"
+readonly JUST_MR="${PWD}/bin/mr-tool-under-test"
+
+readonly LBR="${TEST_TMPDIR}/local-build-root"
+
+readonly LOCAL_DIR="${TEST_TMPDIR}/local"
+readonly ABSENT_DIR="${TEST_TMPDIR}/absent"
+
+readonly DISPATCH_FILE="${TEST_TMPDIR}/dispatch.json"
+
+cat > "${DISPATCH_FILE}" <<EOF
+[[{"runner": "node-name"}, "127.0.0.1:1234"]]
+EOF
+
+readonly REMOTE_PROPERTIES="--remote-execution-property foo:bar"
+readonly DISPATCH="--endpoint-configuration ${DISPATCH_FILE}"
+
+# Set up sample repository
+readonly GENERATOR="${TEST_TMPDIR}/generate.sh"
+readonly GEN_DIR="{TEST_TMPDIR}/gen-dir"
+cat > "${GENERATOR}" <<EOF
+#!/bin/sh
+
+cat > TARGETS <<ENDTARGETS
+{ "main-internal":
+ { "type": "generic"
+ , "cmds": ["echo hello from just-serve > out.txt"]
+ , "outs": ["out.txt"]
+ }
+, "main":
+ {"type": "export", "target": "main-internal", "flexible_config": ["ENV"]}
+}
+ENDTARGETS
+EOF
+
+cat "${GENERATOR}"
+
+chmod 755 "${GENERATOR}"
+mkdir -p "${GEN_DIR}"
+( cd "${GEN_DIR}"
+ git init
+ git config user.email "nobody@example.org"
+ git config user.name "Nobody"
+ "${GENERATOR}"
+ git add .
+ git commit -m "first commit"
+)
+readonly TREE_ID=$(cd "${GEN_DIR}" && git log -n 1 --format="%T")
+
+# fill the target cache that will be used by just serve
+mkdir -p ${LOCAL_DIR}
+( cd ${LOCAL_DIR}
+touch ROOT
+cat > repos.json <<EOF
+{ "repositories":
+ { "":
+ { "repository":
+ { "type": "git tree"
+ , "id": "${TREE_ID}"
+ , "cmd": ["${GENERATOR}"]
+ }
+ }
+ }
+}
+EOF
+echo "local repos configuration:"
+cat repos.json
+echo
+CONF=$("${JUST_MR}" --norc --local-build-root "${SERVE_LBR}" setup)
+
+echo "generated conf":
+cat "${CONF}"
+echo
+
+"${JUST}" build \
+ --local-build-root "${SERVE_LBR}" \
+ -C "${CONF}" \
+ -r "${REMOTE_EXECUTION_ADDRESS}" \
+ ${REMOTE_PROPERTIES} \
+ ${DISPATCH} \
+ main
+)
+
+ls -R "${SERVE_LBR}"
+
+# test with the absent repository
+mkdir -p "${ABSENT_DIR}"
+( cd "${ABSENT_DIR}"
+touch ROOT
+cat > repos.json <<EOF
+{ "repositories":
+ { "":
+ { "repository":
+ { "type": "git tree"
+ , "id": "${TREE_ID}"
+ , "cmd": ["${GENERATOR}"]
+ , "pragma": {"absent": true}
+ }
+ }
+ }
+}
+EOF
+echo "absent repos configuration:"
+cat repos.json
+echo
+
+rm "${GENERATOR}"
+
+CONF=$("${JUST_MR}" --norc --local-build-root "${LBR}" setup)
+cat "${CONF}"
+echo
+# test that it fails without using just serve
+"${JUST}" build --local-build-root "${LBR}" -C "${CONF}" main && echo "this should fail" && exit 1
+echo "failed as expected"
+
+# test that we can successfully compile using just serve
+"${JUST}" build \
+ --local-build-root "${LBR}" \
+ --remote-serve-address "${SERVE}" \
+ -C "${CONF}" \
+ -r "${REMOTE_EXECUTION_ADDRESS}" \
+ ${REMOTE_PROPERTIES} \
+ ${DISPATCH} \
+ main
+)
diff --git a/test/end-to-end/serve-service/serve_target_remote_build.sh b/test/end-to-end/serve-service/serve_target_remote_build.sh
new file mode 100644
index 00000000..66138476
--- /dev/null
+++ b/test/end-to-end/serve-service/serve_target_remote_build.sh
@@ -0,0 +1,63 @@
+#!/bin/sh
+# Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+###########################################################################
+#
+# This script aims to test the "remote build capabilities" of a just-serve
+# instance.
+#
+###########################################################################
+
+set -eu
+
+env
+readonly JUST="${PWD}/bin/tool-under-test"
+readonly JUST_MR="${PWD}/bin/mr-tool-under-test"
+readonly LBR="${TEST_TMPDIR}/local-build-root"
+
+mkdir work
+cd work
+touch ROOT
+cat > repos.json <<EOF
+{ "repositories":
+ { "":
+ { "repository":
+ { "type": "git"
+ , "commit": "$COMMIT_0"
+ , "pragma": {"absent": true}
+ , "repository": "http://non-existent.example.org/data.git"
+ , "branch": "master"
+ , "subdir": "greetlib/greet"
+ }
+ }
+ }
+}
+EOF
+
+CONF=$("${JUST_MR}" --norc --local-build-root "${LBR}" \
+ --remote-serve-address ${SERVE} \
+ -r ${REMOTE_EXECUTION_ADDRESS} \
+ setup)
+cat $CONF
+
+# this test is expected to fail until the just serve implements orchestration of
+# remote build
+${JUST} build --local-build-root "${LBR}" -C "${CONF}" \
+ --remote-serve-address ${SERVE} \
+ --log-limit 8 \
+ -r "${REMOTE_EXECUTION_ADDRESS}" greet 2>&1 && \
+ echo "This test should fail" && exit 1
+
+echo OK