Skip to content

Commit

Permalink
fix: Increase timeout for app container builds
Browse files Browse the repository at this point in the history
  • Loading branch information
doosuu committed Sep 26, 2023
1 parent 746837c commit fd90cc1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
43 changes: 23 additions & 20 deletions runtime_kanto/test/integration/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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)
Expand All @@ -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
)
Expand All @@ -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():
Expand All @@ -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
Expand Down
23 changes: 13 additions & 10 deletions runtime_local/test/integration/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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
)
Expand Down

0 comments on commit fd90cc1

Please sign in to comment.