Skip to content

Commit 782c29a

Browse files
test(python): fix timeout
1 parent 1ae5166 commit 782c29a

3 files changed

Lines changed: 3893 additions & 5777 deletions

File tree

‎crates/python/tests/test_black_box.py‎

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from __future__ import annotations
88
from typing_extensions import TYPE_CHECKING
9-
from concurrent.futures import ThreadPoolExecutor
9+
from concurrent.futures import Executor, ThreadPoolExecutor
1010
from os import environ
1111
from pathlib import Path
1212

@@ -24,7 +24,7 @@
2424
from .deepequals import assert_deep_equal, assert_not_deep_equal
2525

2626
# 并行 workers 数
27-
MAX_WORKERS = 2
27+
MAX_WORKERS = int(environ.get("MAX_WORKERS", "2"))
2828

2929
# 跳过大型文件
3030
SKIP_HUGE = environ.get("SKIP_HUGE", "0") != "0"
@@ -127,22 +127,14 @@ def test_mira_file(mira_file: Path) -> None:
127127
if is_huge and SKIP_HUGE:
128128
pytest.skip("Skipping huge test file")
129129

130-
pool = ThreadPoolExecutor(max_workers=MAX_WORKERS) if MAX_WORKERS > 0 else None
131-
132-
try:
133-
timeout_fns = None
134-
config_checkpoint(120 if is_huge else 10)
135-
if pool is not None:
136-
futures = [
137-
pool.submit(_run_mira_file, mira_file) for _ in range(MAX_WORKERS)
138-
]
139-
timeout_fns = _run_mira_file(mira_file)
140-
for future in futures:
141-
future.result()
142-
else:
143-
timeout_fns = _run_mira_file(mira_file)
130+
with (
131+
ThreadPoolExecutor(max_workers=MAX_WORKERS) if MAX_WORKERS > 0 else Executor()
132+
) as pool:
133+
config_checkpoint(300 if is_huge else 10)
134+
135+
for _ in range(MAX_WORKERS):
136+
pool.submit(_run_mira_file, mira_file)
137+
138+
timeout_fns = _run_mira_file(mira_file)
144139
config_checkpoint() # 重置检查点配置
145140
_run_timeout_fns(timeout_fns)
146-
finally:
147-
if pool is not None:
148-
pool.shutdown(wait=False)

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "mirascript",
33
"version": "0.1.74",
44
"private": true,
5-
"packageManager": "pnpm@11.11.0",
5+
"packageManager": "pnpm@11.15.1",
66
"type": "module",
77
"engines": {
88
"node": ">= 20"

0 commit comments

Comments
 (0)