From d91eeee3ae86af783334d94b888de1ad0e85aded Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 2 Jul 2024 06:53:26 +0800 Subject: [PATCH] Add protection against infinite startup. --- testbed/tests/testbed.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/testbed/tests/testbed.py b/testbed/tests/testbed.py index 92ae8efe8c..23a262b1e1 100644 --- a/testbed/tests/testbed.py +++ b/testbed/tests/testbed.py @@ -16,13 +16,26 @@ def run_tests(app, cov, args, report_coverage, run_slow, running_in_ci): try: # Wait for the app's main window to be visible. Retrieving the actual main window - # will raise an exception until the app is actually initialized, so we check the - # underlying variable. + # will raise an exception until the app is actually initialized. print("Waiting for app to be ready for testing... ", end="", flush=True) - while app._main_window is app._UNDEFINED: - time.sleep(0.05) - while not app.main_window.visible: + i = 0 + ready = False + while i < 100 and not ready: + try: + main_window = app.main_window + if main_window.visible: + ready = True + except ValueError: + pass + time.sleep(0.05) + i += 1 + + if not ready: + print("\nApp didn't display a main window.") + app.returncode = 1 + return + print("ready.") # Control the run speed of the test app. app.run_slow = run_slow