-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[None][test] Dump a stack traceback when a test hangs #16374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BowenFu
wants to merge
6
commits into
NVIDIA:main
Choose a base branch
from
BowenFu:feat/hang-traceback-on-timeout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8e0a537
[None][test] Dump a stack traceback when a test hangs
BowenFu fb5459c
Merge branch 'main' into feat/hang-traceback-on-timeout
BowenFu 2734625
Merge branch 'main' into feat/hang-traceback-on-timeout
BowenFu 4562138
Merge branch 'main' into feat/hang-traceback-on-timeout
BowenFu 1d39738
Merge branch 'main' into feat/hang-traceback-on-timeout
BowenFu 76e2aa2
Merge branch 'main' into feat/hang-traceback-on-timeout
BowenFu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """Unit tests for the hang-traceback dumping in PeriodicJUnitXML. | ||
|
|
||
| These exercise the pure-Python wiring only (timeout resolution and the watchdog | ||
| that writes output-dir/hang_traceback.txt); they need no GPU or model access. | ||
| """ | ||
|
|
||
| import os | ||
| import time | ||
|
|
||
| from .periodic_junit import PeriodicJUnitXML | ||
|
|
||
|
|
||
| class _Marker: | ||
| def __init__(self, args=(), kwargs=None): | ||
| self.args = args | ||
| self.kwargs = kwargs or {} | ||
|
|
||
|
|
||
| class _Config: | ||
| def __init__(self, timeout=None): | ||
| self._timeout = timeout | ||
|
|
||
| def getoption(self, name, default=None): | ||
| return self._timeout if name == "timeout" else default | ||
|
|
||
|
|
||
| class _Item: | ||
| def __init__(self, nodeid="pkg/test_x.py::test_y", timeout_opt=None, marker=None): | ||
| self.nodeid = nodeid | ||
| self.config = _Config(timeout_opt) | ||
| self._marker = marker | ||
|
|
||
| def get_closest_marker(self, name): | ||
| return self._marker | ||
|
|
||
|
|
||
| def _make(tmp_path, **kwargs): | ||
| reporter = PeriodicJUnitXML( | ||
| xmlpath=os.path.join(tmp_path, "results.xml"), dump_hang_traceback=True, **kwargs | ||
| ) | ||
| reporter._setup_hang_dump() | ||
| return reporter | ||
|
|
||
|
|
||
| def test_effective_timeout_resolution(tmp_path): | ||
| reporter = _make(str(tmp_path)) | ||
| # positional marker, keyword marker, and the global --timeout all resolve. | ||
| assert reporter._effective_timeout(_Item(marker=_Marker(args=(90,)))) == 90.0 | ||
| assert reporter._effective_timeout(_Item(marker=_Marker(kwargs={"timeout": 45}))) == 45.0 | ||
| assert reporter._effective_timeout(_Item(timeout_opt=120)) == 120.0 | ||
| # no marker and no --timeout -> no watchdog. | ||
| assert reporter._effective_timeout(_Item()) is None | ||
|
|
||
|
|
||
| def test_hang_dumps_traceback(tmp_path): | ||
| reporter = _make(str(tmp_path), hang_dump_fraction=0.5) | ||
| # timeout 2s * 0.5 -> dump after ~1s. | ||
| reporter.pytest_runtest_setup(_Item(timeout_opt=2.0)) | ||
| time.sleep(1.4) | ||
| content = open(reporter._hang_traceback_path(), encoding="utf-8").read() | ||
| assert "hang watchdog fired for pkg/test_x.py::test_y" in content | ||
| assert "Thread" in content or 'File "' in content | ||
|
|
||
|
|
||
| def test_completed_test_is_not_dumped(tmp_path): | ||
| reporter = _make(str(tmp_path), hang_dump_fraction=0.5) | ||
| reporter.pytest_runtest_setup(_Item(timeout_opt=2.0)) | ||
| time.sleep(0.2) | ||
| reporter._cancel_hang_timer() # what the next setup / sessionfinish does | ||
| time.sleep(1.2) # past the would-be dump point | ||
| assert os.path.getsize(reporter._hang_traceback_path()) == 0 | ||
|
|
||
|
|
||
| def test_no_watchdog_without_timeout(tmp_path): | ||
| reporter = _make(str(tmp_path)) | ||
| reporter.pytest_runtest_setup(_Item()) # no timeout -> nothing armed | ||
| assert reporter._hang_timer is None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.