Skip to content
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

Timeout exceptions should have stack trace from stuck thread #727

Closed
chrisvest opened this issue Aug 23, 2013 · 3 comments
Closed

Timeout exceptions should have stack trace from stuck thread #727

chrisvest opened this issue Aug 23, 2013 · 3 comments

Comments

@chrisvest
Copy link
Contributor

It would be very helpful if tests with timeouts (I tend to use @Test(timeout = ...)) failed with exceptions that had a stack trace from the thread that was stuck or slow.

If a reference to the executing thread is saved (storing this information somewhere could be the first thing it does), then Thread.getStackTrace() will be available for inspection. The exception itself, however, would need to be special, because exceptions don't normally work with a saved array of stack frames, but instead appears to call into native code to generate the stack frame array every time it is needed.

@dsaff
Copy link
Member

dsaff commented Sep 3, 2013

This is a good idea.

adam-beneschan pushed a commit to adam-beneschan/junit that referenced this issue Sep 24, 2013
@adam-beneschan
Copy link

Hello,

I'm pretty new to open source projects, so I apologize if I don't get all the mechanics of pushing and pulling and branching correct. Anyway, I have a fix for this issue and I'll make a pull request soon unless somebody thinks I fixed it wrong and wants me to change something. Anyway, my thinking is that we wouldn't want to add the stack of the executing thread instead of the stack it's currently displaying, because that would lose information that could be valuable. The fixes I added will cause both stacks to be displayed, if it's determined that some thread (other than the "main" thread used to start the test) was causing a problem. A technical detail: I looked into it but I don't think it's possible for the JRE to tell the program which thread it happened to be executing at the point where the timeout occurs. What I did was to set up a ThreadGroup to hold the thread that runs the test; then any threads created by the test will normally be part of that ThreadGroup or a subgroup. Then it's possible to look for all threads in the group (and subgroups) and see if exactly one is RUNNABLE; if so, it assumes that's the one that's stuck. If there are more than one, it tries to determine which one has used the most CPU time. I think this would provide the kind of information that the requester or another user would find useful.

adam-beneschan pushed a commit to adam-beneschan/junit that referenced this issue Sep 27, 2013
dsaff pushed a commit that referenced this issue Oct 31, 2013
#727 Fail on timeout displays stack of stuck thread
reinholdfuereder added a commit to reinholdfuereder/junit that referenced this issue Nov 22, 2013
junit-team#463: Add ability for timeout to print full thread stack dump
- Naive attempt that (a) optionally adds information from ThreadMXBean#findMonitorDeadlockedThreads and (b) always adds full thread dump to exception message
reinholdfuereder added a commit to reinholdfuereder/junit that referenced this issue Nov 22, 2013
junit-team#463 Add ability for timeout to print full thread stack dump
- Another attempt that allows to "install" an additional custom timeout handler that can optionally also add a further exception to the test timeout exception
reinholdfuereder added a commit to reinholdfuereder/junit that referenced this issue Nov 22, 2013
junit-team#463 Add ability for timeout to print full thread stack dump
- Another attempt that allows to "install" an additional custom timeout handler that can optionally also add a further exception to the test timeout exception
- Fix: remove outdated TODO comment
reinholdfuereder added a commit to reinholdfuereder/junit that referenced this issue Nov 22, 2013
junit-team#463 Add ability for timeout to print full thread stack dump
- Extend the attempt that allows to "install" an additional custom timeout handler (that can optionally also add a further exception to the test timeout exception) by a globally set custom timeout handler based on a system property: note this fails in Ant context; and deadlocked threads of self tests are surviving; so this is by no means finished
reinholdfuereder added a commit to reinholdfuereder/junit that referenced this issue Nov 23, 2013
junit-team#463 Add ability for timeout to print full thread stack dump
- Ref tests and where the test thread is interrupted to prevent surviving threads (as it is the case for other older tests!), reduce duplication in test code
@stefanbirkner
Copy link
Contributor

Fixed by #742.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants