diff options
author | Alberto Sartori <alberto.sartori@huawei.com> | 2023-04-20 13:01:38 +0200 |
---|---|---|
committer | Alberto Sartori <alberto.sartori@huawei.com> | 2023-04-21 09:42:15 +0200 |
commit | 70dffcedcbe6c399038adafd7c8b8555a6bfda26 (patch) | |
tree | 28f0f77b57f7ea84afe09be1d6911cfa980c8916 /test | |
parent | f65776770fbd83a91095db2d346ae0ad3e0bbcef (diff) | |
download | justbuild-70dffcedcbe6c399038adafd7c8b8555a6bfda26.tar.gz |
["test/end-to-end", "with remote"]: allow for the usage of a given remote endpoint
This can be useful, for example, to test if justbuild can successfully
communicate with the specified remote execution service.
Diffstat (limited to 'test')
-rw-r--r-- | test/end-to-end/EXPRESSIONS | 5 | ||||
-rw-r--r-- | test/end-to-end/RULES | 6 | ||||
-rwxr-xr-x | test/end-to-end/with_remote_test_runner.py | 79 |
3 files changed, 61 insertions, 29 deletions
diff --git a/test/end-to-end/EXPRESSIONS b/test/end-to-end/EXPRESSIONS index 20b9cb6a..3348d460 100644 --- a/test/end-to-end/EXPRESSIONS +++ b/test/end-to-end/EXPRESSIONS @@ -7,6 +7,7 @@ , "keep" , "transition" , "TEST_COMPATIBLE_REMOTE" + , "TEST_REMOTE_EXECUTION" ] , "imports": { "artifacts_list": ["@", "rules", "", "field_artifacts_list"] @@ -99,6 +100,9 @@ , "then": "true" , "else": "false" } + , { "type": "json_encode" + , "$1": {"type": "var", "name": "TEST_REMOTE_EXECUTION"} + } ] , {"type": "var", "name": "keep"} ] @@ -166,6 +170,7 @@ , "deps-fieldname" , "transition" , "TEST_COMPATIBLE_REMOTE" + , "TEST_REMOTE_EXECUTION" ] , "imports": {"action": "test-action"} , "expression": diff --git a/test/end-to-end/RULES b/test/end-to-end/RULES index 6c55e8cf..af15181e 100644 --- a/test/end-to-end/RULES +++ b/test/end-to-end/RULES @@ -11,6 +11,7 @@ , "RUNS_PER_TEST" , "TEST_ENV" , "TEST_COMPATIBLE_REMOTE" + , "TEST_REMOTE_EXECUTION" ] , "field_doc": { "test": @@ -44,6 +45,11 @@ , "TEST_ENV": ["The environment for executing the test runner."] , "TEST_COMPATIBLE_REMOTE": ["If true, run the remote execution in compatible mode."] + , "TEST_REMOTE_EXECUTION": + [ "JSON object (aka map) containing at least \"interface\" and \"port\"." + , "If the remote execution service requires additional arguments, they can be listed" + , "in the list of strings named \"args\"." + ] } , "tainted": ["test"] , "artifacts_doc": diff --git a/test/end-to-end/with_remote_test_runner.py b/test/end-to-end/with_remote_test_runner.py index b5f71c5f..c685b2c5 100755 --- a/test/end-to-end/with_remote_test_runner.py +++ b/test/end-to-end/with_remote_test_runner.py @@ -38,6 +38,9 @@ def dump_results(): with open("stderr", "w") as f: f.write("%s\n" % (stderr, )) +def get_remote_execution_address(d): + return "%s:%d" % (d["interface"], int(d["port"])) + dump_results() @@ -49,40 +52,57 @@ os.makedirs(WORK_DIR, exist_ok=True) REMOTE_DIR = os.path.realpath("remote") os.makedirs(REMOTE_DIR, exist_ok=True) -REMOTE_INFO = os.path.join(REMOTE_DIR, "info.json") REMOTE_LBR = os.path.join(REMOTE_DIR, "build-root") -if os.path.exists(REMOTE_INFO): - print(f"Warning: removing unexpected info file {REMOTE_INFO}") - os.remove(REMOTE_INFO) - -remote_cmd = [ - "./just", "execute", - "--info-file", REMOTE_INFO, - "--local-build-root", REMOTE_LBR, - "--log-limit", "6", "--plain-log", -] +REMOTE_EXECUTION_ADDRESS = "" compatible = json.loads(sys.argv[1]) -if compatible: - remote_cmd.append("--compatible") + +custom_remote = json.loads(sys.argv[2]) + +if not custom_remote: + # start just execute as remote service + REMOTE_INFO = os.path.join(REMOTE_DIR, "info.json") + + if os.path.exists(REMOTE_INFO): + print(f"Warning: removing unexpected info file {REMOTE_INFO}") + os.remove(REMOTE_INFO) -remotestdout = open("remotestdout", "w") -remotestderr = open("remotestderr", "w") -remote_proc = subprocess.Popen( - remote_cmd, - stdout=remotestdout, - stderr=remotestderr, -) + remote_cmd = [ + "./just", "execute", + "--info-file", REMOTE_INFO, + "--local-build-root", REMOTE_LBR, + "--log-limit", "6", "--plain-log", + ] -while not os.path.exists(REMOTE_INFO): - time.sleep(1) + if compatible: + remote_cmd.append("--compatible") -with open(REMOTE_INFO) as f: - info = json.load(f) + remotestdout = open("remotestdout", "w") + remotestderr = open("remotestderr", "w") + remote_proc = subprocess.Popen( + remote_cmd, + stdout=remotestdout, + stderr=remotestderr, + ) -REMOTE_EXECUTION_ADDRESS = "%s:%d" % (info["interface"], info["port"]) + while not os.path.exists(REMOTE_INFO): + time.sleep(1) + + with open(REMOTE_INFO) as f: + info = json.load(f) + + REMOTE_EXECUTION_ADDRESS = get_remote_execution_address(info) +else: + msg = "\nA custom remote service is used, please look at logs there.\n" + with open("remotestdout", "w") as f: + print(msg, file=f) + with open("remotestderr", "w") as f: + print(msg, file=f) + + args = custom_remote.get("args",[]) + REMOTE_EXECUTION_ADDRESS = " ".join((get_remote_execution_address(custom_remote), *args)) ENV = dict(os.environ, TEST_TMPDIR=TEMP_DIR, TMPDIR=TEMP_DIR, @@ -97,7 +117,6 @@ for k in ["TLS_CA_CERT", "TLS_CLIENT_CERT", "TLS_CLIENT_KEY"]: if k in ENV: del ENV[k] - time_start = time.time() ret = subprocess.run(["sh", "../test.sh"], cwd=WORK_DIR, @@ -108,13 +127,15 @@ time_stop = time.time() result = "PASS" if ret.returncode == 0 else "FAIL" stdout = ret.stdout.decode("utf-8") stderr = ret.stderr.decode("utf-8") -remote_proc.terminate() -rout, rerr = remote_proc.communicate() + +if not custom_remote: + remote_proc.terminate() + rout, rerr = remote_proc.communicate() dump_results() for f in sys.argv[2:]: - keep_file = os.path.join(WORKDIR, f) + keep_file = os.path.join(WORK_DIR, f) if not os.path.exists(keep_file): open(keep_file, "a").close() |