From fd90cc17bbf2235423db7b3a487090112e61ce77 Mon Sep 17 00:00:00 2001 From: Dominic Sudy Date: Mon, 25 Sep 2023 14:42:03 +0200 Subject: [PATCH] fix: Increase timeout for app container builds --- .../test/integration/integration_test.py | 43 ++++++++++--------- .../test/integration/integration_test.py | 23 +++++----- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/runtime_kanto/test/integration/integration_test.py b/runtime_kanto/test/integration/integration_test.py index 966fd73e..2ff0cdd5 100644 --- a/runtime_kanto/test/integration/integration_test.py +++ b/runtime_kanto/test/integration/integration_test.py @@ -18,18 +18,19 @@ import sys import time from pathlib import Path -from re import Pattern, compile +from re import Pattern +from re import compile as re_compile from subprocess import PIPE, Popen from threading import Timer BASE_COMMAND_RUNTIME = "velocitas exec runtime-kanto" BASE_COMMAND_DEPLOYMENT = "velocitas exec deployment-kanto" -regex_runtime_up: Pattern[str] = compile(r"✅.* Kanto is ready to use!") -regex_build: Pattern[str] = compile(r"✅.* Building VehicleApp...") -regex_deploy: Pattern[str] = compile(r"✅.* Deploying VehicleApp...") -regex_stop: Pattern[str] = compile(r"✅.* Stopping Kanto...") -timeout_sec: float = 120 +regex_runtime_up: Pattern[str] = re_compile(r"✅.* Kanto is ready to use!") +regex_build: Pattern[str] = re_compile(r"✅.* Building VehicleApp...") +regex_deploy: Pattern[str] = re_compile(r"✅.* Deploying VehicleApp...") +regex_stop: Pattern[str] = re_compile(r"✅.* Stopping Kanto...") +DEFAULT_TIMEOUT_SEC: float = 120 def create_dummy_vspec_file(): @@ -41,7 +42,7 @@ def create_dummy_vspec_file(): cache_paths = Path("~/.velocitas/projects").expanduser().rglob("cache.json") for cache_path in cache_paths: vspec_path = cache_path.parent / "dummy_vspec.json" - with open(vspec_path, "w") as dummy_vspec_file: + with open(vspec_path, mode="w", encoding="utf-8") as dummy_vspec_file: dummy_vspec_file.write("{}\n") with open(cache_path, mode="r", encoding="utf-8") as cache_file: cache = json.load(cache_file) @@ -63,7 +64,9 @@ def check_container_is_running(container_name: str) -> bool: )["state"]["running"] -def run_command_until_logs_match(command: str, regex_service: Pattern[str]) -> bool: +def run_command_until_logs_match( + command: str, regex_service: Pattern[str], timeout_sec=DEFAULT_TIMEOUT_SEC +) -> bool: proc: Popen[str] = Popen( command.split(" "), stdout=PIPE, bufsize=1, universal_newlines=True ) @@ -83,17 +86,17 @@ def run_command_until_logs_match(command: str, regex_service: Pattern[str]) -> b def wait_for_container_update(): path = os.path.join(Path.cwd(), "logs/runtime_kanto/container-management.log") - f = open(path, "r") - while True: - line = f.readline() - print(line) - if line.find("finished containers update") != -1: - f.close() - break - # if line is empty and string not found wait for more input - if len(line) == 0: - print("waiting") - time.sleep(1) + with open(path, mode="r", encoding="utf-8") as f: + while True: + line = f.readline() + print(line) + if line.find("finished containers update") != -1: + f.close() + break + # if line is empty and string not found wait for more input + if len(line) == 0: + print("waiting") + time.sleep(1) def test_scripts_run_successfully(): @@ -105,7 +108,7 @@ def test_scripts_run_successfully(): assert check_container_is_running("databroker") assert check_container_is_running("feedercan") assert run_command_until_logs_match( - f"{BASE_COMMAND_DEPLOYMENT} build-vehicleapp", regex_build + f"{BASE_COMMAND_DEPLOYMENT} build-vehicleapp", regex_build, 60 * 12 ) assert run_command_until_logs_match( f"{BASE_COMMAND_DEPLOYMENT} deploy-vehicleapp", regex_deploy diff --git a/runtime_local/test/integration/integration_test.py b/runtime_local/test/integration/integration_test.py index 9d34a8d1..14fba134 100644 --- a/runtime_local/test/integration/integration_test.py +++ b/runtime_local/test/integration/integration_test.py @@ -15,7 +15,8 @@ import json import sys from pathlib import Path -from re import Pattern, compile +from re import Pattern +from re import compile as re_compile from subprocess import PIPE, Popen from threading import Timer @@ -29,7 +30,7 @@ def create_dummy_vspec_file(): cache_paths = Path("~/.velocitas/projects").expanduser().rglob("cache.json") for cache_path in cache_paths: vspec_path = cache_path.parent / "dummy_vspec.json" - with open(vspec_path, "w") as dummy_vspec_file: + with open(vspec_path, "w", encoding="utf-8") as dummy_vspec_file: dummy_vspec_file.write("{}\n") with open(cache_path, mode="r", encoding="utf-8") as cache_file: cache = json.load(cache_file) @@ -39,16 +40,18 @@ def create_dummy_vspec_file(): command: str = "velocitas exec runtime-local" -regex_runtime_up: Pattern[str] = compile(r"✅.* Runtime is ready to use!") -regex_mqtt: Pattern[str] = compile(r"✅.* Starting service mqtt") -regex_vdb: Pattern[str] = compile(r"✅.* Starting service vehicledatabroker") -regex_seatservice: Pattern[str] = compile(r"✅.* Starting service seatservice") -regex_feedercan: Pattern[str] = compile(r"✅.* Starting service feedercan") -regex_mockservice: Pattern[str] = compile(r"✅.* Starting service mockservice") -timeout_sec: float = 180 +regex_runtime_up: Pattern[str] = re_compile(r"✅.* Runtime is ready to use!") +regex_mqtt: Pattern[str] = re_compile(r"✅.* Starting service mqtt") +regex_vdb: Pattern[str] = re_compile(r"✅.* Starting service vehicledatabroker") +regex_seatservice: Pattern[str] = re_compile(r"✅.* Starting service seatservice") +regex_feedercan: Pattern[str] = re_compile(r"✅.* Starting service feedercan") +regex_mockservice: Pattern[str] = re_compile(r"✅.* Starting service mockservice") +DEFAULT_TIMEOUT_SEC: float = 180 -def run_command_until_logs_match(command: str, regex_service: Pattern[str]) -> bool: +def run_command_until_logs_match( + command: str, regex_service: Pattern[str], timeout_sec=DEFAULT_TIMEOUT_SEC +) -> bool: proc: Popen[str] = Popen( command.split(" "), stdout=PIPE, bufsize=1, universal_newlines=True )