From 767716edc1a2aa930dd142a42a2d664addf151c1 Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Fri, 20 Oct 2023 17:43:45 +0200 Subject: just-serve: add end-to-end tests serve_target_remote_build.sh should be updated once just-serve can orchestrate the remote build --- test/end-to-end/TARGETS | 40 ++++-- test/end-to-end/serve-service/TARGETS | 39 +++++ test/end-to-end/serve-service/serve_export_deps.sh | 159 +++++++++++++++++++++ .../serve-service/serve_start_execute.sh | 79 ++++++++++ .../serve-service/serve_target_cache_hit.sh | 153 ++++++++++++++++++++ .../serve-service/serve_target_remote_build.sh | 63 ++++++++ 6 files changed, 518 insertions(+), 15 deletions(-) create mode 100644 test/end-to-end/serve-service/TARGETS create mode 100644 test/end-to-end/serve-service/serve_export_deps.sh create mode 100644 test/end-to-end/serve-service/serve_start_execute.sh create mode 100644 test/end-to-end/serve-service/serve_target_cache_hit.sh create mode 100644 test/end-to-end/serve-service/serve_target_remote_build.sh (limited to 'test') diff --git a/test/end-to-end/TARGETS b/test/end-to-end/TARGETS index 4ec2fe5d..ef7242b2 100644 --- a/test/end-to-end/TARGETS +++ b/test/end-to-end/TARGETS @@ -50,22 +50,32 @@ } , "TESTS": { "type": "install" + , "arguments_config": ["TEST_BOOTSTRAP_JUST_MR"] , "tainted": ["test"] , "dirs": - [ [["./", "actions", "TESTS"], "actions"] - , [["./", "cli", "TESTS"], "cli"] - , [["./", "generated-binary", "TESTS"], "generated-binary"] - , [["./", "target-tests", "TESTS"], "targets"] - , [["./", "user-errors", "TESTS"], "user-errors"] - , [["./", "built-in-rules", "TESTS"], "built-in-rules"] - , [["./", "build-fails", "TESTS"], "build-fails"] - , [["./", "remote-execution", "TESTS"], "remote-execution"] - , [["./", "target-cache", "TESTS"], "target-cache"] - , [["./", "just-mr", "TESTS"], "just-mr"] - , [["./", "git-import", "TESTS"], "git-import"] - , [["./", "gc", "TESTS"], "gc"] - , [["./", "execution-service", "TESTS"], "execution-service"] - , [["./", "symlinks", "TESTS"], "symlinks"] - ] + { "type": "++" + , "$1": + [ [ [["./", "actions", "TESTS"], "actions"] + , [["./", "cli", "TESTS"], "cli"] + , [["./", "generated-binary", "TESTS"], "generated-binary"] + , [["./", "target-tests", "TESTS"], "targets"] + , [["./", "user-errors", "TESTS"], "user-errors"] + , [["./", "built-in-rules", "TESTS"], "built-in-rules"] + , [["./", "build-fails", "TESTS"], "build-fails"] + , [["./", "remote-execution", "TESTS"], "remote-execution"] + , [["./", "target-cache", "TESTS"], "target-cache"] + , [["./", "just-mr", "TESTS"], "just-mr"] + , [["./", "git-import", "TESTS"], "git-import"] + , [["./", "gc", "TESTS"], "gc"] + , [["./", "execution-service", "TESTS"], "execution-service"] + , [["./", "symlinks", "TESTS"], "symlinks"] + ] + , { "type": "if" + , "cond": {"type": "var", "name": "TEST_BOOTSTRAP_JUST_MR"} + , "then": [] + , "else": [[["./", "serve-service", "TESTS"], "serve-service"]] + } + ] + } } } 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}" < TARGETS < 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 < "${GENERATOR_LOCAL}" < TARGETS < 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 < .just-servec <&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 < 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}" < "${GENERATOR}" < TARGETS < 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 < repos.json < repos.json <&1 && \ + echo "This test should fail" && exit 1 + +echo OK -- cgit v1.2.3