From f40dc0075763bbf8cb60542f52f99519156b95eb Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 27 May 2025 15:05:37 +0200 Subject: [PATCH] raise an exception if the pull socket python script had errors at startup (for eg if pyzmq was not installed) --- tests/scripts/test_frame_synchronizer.py | 4 ++++ tests/scripts/utils_for_test.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/scripts/test_frame_synchronizer.py b/tests/scripts/test_frame_synchronizer.py index 87c784cf7..3c2192c3b 100644 --- a/tests/scripts/test_frame_synchronizer.py +++ b/tests/scripts/test_frame_synchronizer.py @@ -20,6 +20,7 @@ from utils_for_test import ( cleanSharedmemory, startProcessInBackground, startProcessInBackgroundWithLogFile, + checkLogForErrors, startDetectorVirtualServer, loadConfig, ParseArguments @@ -34,6 +35,9 @@ def startFrameSynchronizerPullSocket(name, fp): fname = PULL_SOCKET_PREFIX_FNAME + name + '.txt' cmd = ['python', '-u', 'frameSynchronizerPullSocket.py'] startProcessInBackgroundWithLogFile(cmd, fp, fname) + time.sleep(1) + checkLogForErrors(fp, fname) + def startFrameSynchronizer(num_mods, fp): diff --git a/tests/scripts/utils_for_test.py b/tests/scripts/utils_for_test.py index f2ca16cee..c3f086520 100644 --- a/tests/scripts/utils_for_test.py +++ b/tests/scripts/utils_for_test.py @@ -104,7 +104,7 @@ def startProcessInBackground(cmd, fp): raise RuntimeException(f'Failed to start {cmd}:{str(e)}') from e -def startProcessInBackgroundWithLogFile(cmd, fp, log_file_name): +def startProcessInBackgroundWithLogFile(cmd, fp, log_file_name: str): Log(LogLevel.INFOBLUE, 'Starting up ' + ' '.join(cmd) + '. Log: ' + log_file_name) Log(LogLevel.INFOBLUE, 'Starting up ' + ' '.join(cmd) + '. Log: ' + log_file_name, fp) try: @@ -114,6 +114,22 @@ def startProcessInBackgroundWithLogFile(cmd, fp, log_file_name): raise RuntimeException(f'Failed to start {cmd}:{str(e)}') from e +def checkLogForErrors(fp, log_file_path: str): + try: + with open(log_file_path, 'r') as log_file: + for line in log_file: + if 'Error' in line: + Log(LogLevel.ERROR, f"Error found in log: {line.strip()}") + Log(LogLevel.ERROR, f"Error found in log: {line.strip()}", fp) + raise RuntimeException("Error found in log file") + except FileNotFoundError: + print(f"Log file not found: {log_file_path}") + raise + except Exception as e: + print(f"Exception while reading log: {e}") + raise + + def runProcessWithLogFile(name, cmd, fp, log_file_name): Log(LogLevel.INFOBLUE, 'Running ' + name + '. Log: ' + log_file_name) Log(LogLevel.INFOBLUE, 'Running ' + name + '. Log: ' + log_file_name, fp)