Skip to content

Commit 129b408

Browse files
msyycCopilot
andauthored
Add optional timeout parameter to sdk_changelog tool (#45612)
Add --timeout CLI argument (in seconds) to the sdk_changelog tool, threaded through main() and get_changelog_content() to execute_func_with_timeout(). Defaults to 900s when not specified. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6a69095 commit 129b408

2 files changed

Lines changed: 38 additions & 5 deletions

File tree

eng/tools/azure-sdk-tools/packaging_tools/sdk_changelog.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ def execute_func_with_timeout(func, timeout: int = 900) -> Any:
4343
return multiprocessing.Pool(processes=1).apply_async(func).get(timeout)
4444

4545

46-
def get_changelog_content(package_path: Path, package_result: dict, enable_changelog: bool) -> tuple[str, str]:
46+
def get_changelog_content(
47+
package_path: Path, package_result: dict, enable_changelog: bool, timeout: int = 900
48+
) -> tuple[str, str]:
4749
"""Generate changelog content for the given package path.
4850
Args:
4951
package_path (Path): The path to the package directory.
5052
package_result (dict): The package result dictionary to store changelog info.
5153
enable_changelog (bool): Flag to enable or disable changelog generation.
54+
timeout (int): Timeout in seconds for changelog generation. Defaults to 900.
5255
Returns:
5356
tuple[str, str]: A tuple containing the generated markdown content and the last version.
5457
NOTE:
@@ -79,7 +82,7 @@ def get_changelog_content(package_path: Path, package_result: dict, enable_chang
7982

8083
try:
8184
if enable_changelog:
82-
md_output = execute_func_with_timeout(change_log_func)
85+
md_output = execute_func_with_timeout(change_log_func, timeout)
8386
else:
8487
md_output = "skip changelog generation"
8588
except multiprocessing.TimeoutError:
@@ -104,7 +107,7 @@ def log_failed_message(message: str, enable_log_error: bool):
104107
_LOGGER.warning(message)
105108

106109

107-
def main(package_path: Path, *, enable_changelog: bool = True, package_result: dict = {}):
110+
def main(package_path: Path, *, enable_changelog: bool = True, package_result: dict = {}, timeout: int = 900):
108111

109112
package_name = package_path.name
110113
# When package_result is provided, it means this function is called in pipeline and we should not log error
@@ -113,7 +116,7 @@ def main(package_path: Path, *, enable_changelog: bool = True, package_result: d
113116
# Changelog generation
114117
try:
115118
changelog_generation_start_time = time.time()
116-
md_output, last_version = get_changelog_content(package_path, package_result, enable_changelog)
119+
md_output, last_version = get_changelog_content(package_path, package_result, enable_changelog, timeout=timeout)
117120
_LOGGER.info(f"changelog generation cost time: {int(time.time() - changelog_generation_start_time)} seconds")
118121
if package_result:
119122
package_result["changelog"] = {
@@ -183,6 +186,12 @@ def generate_main():
183186
required=True,
184187
help="Absolute path to the package directory (e.g. c:/azure-sdk-for-python/sdk/<service>/<package_name>).",
185188
)
189+
parser.add_argument(
190+
"--timeout",
191+
type=int,
192+
default=900,
193+
help="Timeout in seconds for changelog generation (default: 900).",
194+
)
186195
parser.add_argument("--debug", dest="debug", action="store_true", help="Enable DEBUG logging")
187196

188197
args = parser.parse_args()
@@ -198,7 +207,7 @@ def generate_main():
198207
if not package_path.is_absolute():
199208
raise ValueError("--package-path must be an absolute path")
200209

201-
main(package_path)
210+
main(package_path, timeout=args.timeout)
202211

203212

204213
if __name__ == "__main__":

eng/tools/azure-sdk-tools/tests/test_sdk_changelog.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,27 @@ def mock_log_failed_message(message: str, enable_log_error: bool):
156156

157157
assert not called
158158
assert log_level is None, "Expected no error log for invalid changelog content in data-plane SDK"
159+
160+
161+
@patch("packaging_tools.sdk_changelog.get_changelog_content")
162+
def test_timeout_forwarded_to_get_changelog_content(mock_get_changelog_content, temp_package):
163+
package_path, _ = temp_package
164+
mock_get_changelog_content.return_value = ("### Features Added\n\n- New feature", "1.0.0")
165+
166+
changelog_main(package_path, timeout=60)
167+
168+
mock_get_changelog_content.assert_called_once()
169+
_, kwargs = mock_get_changelog_content.call_args
170+
assert kwargs["timeout"] == 60
171+
172+
173+
@patch("packaging_tools.sdk_changelog.get_changelog_content")
174+
def test_timeout_default_is_900(mock_get_changelog_content, temp_package):
175+
package_path, _ = temp_package
176+
mock_get_changelog_content.return_value = ("### Features Added\n\n- New feature", "1.0.0")
177+
178+
changelog_main(package_path)
179+
180+
mock_get_changelog_content.assert_called_once()
181+
_, kwargs = mock_get_changelog_content.call_args
182+
assert kwargs["timeout"] == 900

0 commit comments

Comments
 (0)