Skip to content

Commit 3735786

Browse files
committed
Adding a test script timeout argument
1 parent a2ccfa8 commit 3735786

8 files changed

Lines changed: 25 additions & 8 deletions

module_renderer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def _build_render_context_for_module(
176176
verbose=self.args.verbose,
177177
run_state=self.run_state,
178178
event_bus=self.event_bus,
179+
test_script_timeout=self.args.test_script_timeout,
179180
)
180181

181182
def _render_module(

plain2code.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
from system_config import system_config
4848
from tui.plain2code_tui import Plain2CodeTUI
4949

50-
TEST_SCRIPT_EXECUTION_TIMEOUT = 120 # 120 seconds
51-
5250
DEFAULT_TEMPLATE_DIRS = importlib.resources.files("standard_template_library")
5351

5452
MAX_UNITTEST_FIX_ATTEMPTS = 20

plain2code_arguments.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ def create_parser():
202202
help="Path to a shell script that prepares the testing environment. The script should accept the source code folder path as its first argument.",
203203
)
204204

205+
parser.add_argument(
206+
"--test-script-timeout",
207+
type=int,
208+
default=None,
209+
help="Timeout for test scripts in seconds. If not provided, the default timeout of 120 seconds is used.",
210+
)
211+
205212
parser.add_argument(
206213
"--api",
207214
type=str,

render_machine/actions/prepare_testing_environment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |
2121
[render_context.build_folder],
2222
render_context.verbose,
2323
"Testing Environment Preparation",
24+
timeout=render_context.test_script_timeout,
2425
)
2526

2627
render_context.conformance_tests_running_context.should_prepare_testing_environment = False

render_machine/actions/run_conformance_tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |
4343
[render_context.build_folder, conformance_tests_folder_name],
4444
render_context.verbose,
4545
"Conformance Tests",
46-
render_context.conformance_tests_running_context.current_testing_frid,
46+
frid=render_context.conformance_tests_running_context.current_testing_frid,
47+
timeout=render_context.test_script_timeout,
4748
)
4849
render_context.script_execution_history.latest_conformance_test_output_path = conformance_tests_temp_file_path
4950
render_context.script_execution_history.should_update_script_outputs = True

render_machine/actions/run_unit_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |
2424
[render_context.build_folder],
2525
render_context.verbose,
2626
"Unit Tests",
27+
timeout=render_context.test_script_timeout,
2728
)
2829

2930
render_context.script_execution_history.latest_unit_test_output_path = unittests_temp_file_path

render_machine/render_context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def __init__(
5151
verbose: bool,
5252
run_state: RunState,
5353
event_bus: EventBus,
54+
test_script_timeout: Optional[int] = None,
5455
):
5556
self.codeplain_api: CodeplainAPI = codeplain_api
5657
self.memory_manager = memory_manager
@@ -75,6 +76,7 @@ def __init__(
7576
self.event_bus = event_bus
7677
self.script_execution_history = ScriptExecutionHistory()
7778
self.starting_frid = None
79+
self.test_script_timeout = test_script_timeout
7880

7981
resources_list = []
8082
plain_spec.collect_linked_resources(plain_source_tree, resources_list, None, True)

render_machine/render_utils.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,23 @@ def print_inputs(render_context, existing_files_content, message):
4242

4343

4444
def execute_script(
45-
script: str, scripts_args: list[str], verbose: bool, script_type: str, frid: Optional[str] = None
45+
script: str,
46+
scripts_args: list[str],
47+
verbose: bool,
48+
script_type: str,
49+
frid: Optional[str] = None,
50+
timeout: Optional[int] = None,
4651
) -> tuple[int, str, Optional[str]]:
4752
temp_file_path = None
53+
script_timeout = timeout if timeout is not None else SCRIPT_EXECUTION_TIMEOUT
4854
try:
4955
start_time = time.time()
5056
result = subprocess.run(
5157
[file_utils.add_current_path_if_no_path(script)] + scripts_args,
5258
stdout=subprocess.PIPE,
5359
stderr=subprocess.STDOUT,
5460
text=True,
55-
timeout=SCRIPT_EXECUTION_TIMEOUT,
61+
timeout=script_timeout,
5662
)
5763
elapsed_time = time.time() - start_time
5864
# Log the info about the script execution
@@ -90,19 +96,19 @@ def execute_script(
9096
# Store timeout output in a temporary file
9197
if verbose:
9298
with tempfile.NamedTemporaryFile(mode="w+", delete=False, suffix=".script_timeout") as temp_file:
93-
temp_file.write(f"{script_type} script {script} timed out after {SCRIPT_EXECUTION_TIMEOUT} seconds.")
99+
temp_file.write(f"{script_type} script {script} timed out after {script_timeout} seconds.")
94100
if e.stdout:
95101
decoded_output = e.stdout.decode("utf-8") if isinstance(e.stdout, bytes) else e.stdout
96102
temp_file.write(f"{script_type} script partial output before the timeout:\n{decoded_output}")
97103
else:
98104
temp_file.write(f"{script_type} script did not produce any output before the timeout.")
99105
temp_file_path = temp_file.name
100106
console.warning(
101-
f"The {script_type} script timed out after {SCRIPT_EXECUTION_TIMEOUT} seconds. {script_type} script output stored in: {temp_file_path}"
107+
f"The {script_type} script timed out after {script_timeout} seconds. {script_type} script output stored in: {temp_file_path}"
102108
)
103109

104110
return (
105111
TIMEOUT_ERROR_EXIT_CODE,
106-
f"{script_type} script did not finish in {SCRIPT_EXECUTION_TIMEOUT} seconds.",
112+
f"{script_type} script did not finish in {script_timeout} seconds.",
107113
temp_file_path,
108114
)

0 commit comments

Comments
 (0)