-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
#727 Fail on timeout displays stack of stuck thread #742
Conversation
* Returns the relevant thread for the exception. | ||
* @return The relevant thread. | ||
*/ | ||
public Thread getThread () { return fThread; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you reformat to match the formatting of the surrounding classes?
Thank you very much for tackling this. This is a good direction. |
You're welcome. I'll take a look at your suggestions soon. |
@dsaff I've made the changes you suggested. Since the new version has just one changed file (FailOnTimeout.java) instead of two changed files and one new one, I created a branch in my repo, issue727-2. (Changes to Failure.java have all been backed out.) Do I need to make another pull request, or is this notification sufficient, or is there anything else I need to do? I'm still trying to learn the mechanics of GitHub; apologies if I did something wrong. The "master" branch in my repo is still the changes from three days ago, so it isn't what you want. Also let me know if there's an indentation problem; things look fine in Eclipse but I was having some problems with tabs. I noticed that with MultipleFailureException, a failure that also displays the stack of a "stuck" thread will now be counted as 2 failures. Maybe that's best. If not, and if it ought to be counted as one failure, I'm sure something could be done (possibly a boolean field in MultipleFailureException to indicate the multiple exceptions are "really just different aspects of one failure", or maybe there's a better solution). |
You'll need to create a new commit on the same branch, and then push it to your repo. No problem, GitHub takes turning your head sideways for a while until it starts making sense. I think two failures is fine; when I can take a look at the new commit, I can comment more. |
OK, I hope I did it right this time. Thanks for your help. -----Original Message----- @adam-beneschan, |
@@ -26,7 +31,8 @@ public FailOnTimeout(Statement originalStatement, long timeout, TimeUnit unit) { | |||
@Override | |||
public void evaluate() throws Throwable { | |||
FutureTask<Throwable> task = new FutureTask<Throwable>(new CallableStatement()); | |||
Thread thread = new Thread(task, "Time-limited test"); | |||
fThreadGroup = new ThreadGroup ("FailOnTimeoutGroup"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still odd indentation here.
I like this version. Some structure and formatting questions. You can take a look on GitHub to see if spaces and tabs are matching up: we generally indent just with spaces. It should be possible to write a self-test for this feature, don't you think? |
@dsaff OK, I've made the improvements you suggested. (I got Eclipse to stop generating tab characters.) Also, I added two test cases to org.junit.tests.running.methods.TimeoutTest (one multithreaded case where a "stuck thread" should show up, and another multithreaded case where the main thread is the stuck one so the result shouldn't look any different). I couldn't figure out what org.junit.tests.internal.runners.statements.FailOnTimeoutTest was; it doesn't seem to be referenced by anything else. Is that something that needs modification also? |
"test timed out after %d %s", fTimeout, fTimeUnit.name().toLowerCase())); | ||
if (stuckThread != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we move this below the if (stackTrace != null) check below, then we can just use return statements, rather than the resultException local
Quite nice. A sprinkling of style requests throughout. Could this create problems for anyone? I'm explicitly wondering what the computational costs of the thread enumeration are, and whether they're high enough that someone might want a switch to turn it off? |
Thanks! Can you add notes at https://github.com/junit-team/junit/wiki/4.12-release-notes? Thanks. |
Oh no! Arrays.copyOf is Java 1.6, and we're still trying to maintain compatibility down to 1.5. Can you make a follow-on pull request with a fix? Thanks. |
@dsaff Done (for #742). I can do #759 after it's merged (removed use of Arrays.copyOf). Thanks for all your help with the GitHub mechanics. I'm hoping to be able to make more contributions to JUnit in the future. Thanks, Adam -----Original Message----- Thanks! Can you add notes at https://github.com/junit-team/junit/wiki/4.12-release-notes? Thanks. |
@dsaff Java 5 reached end of life on October, 2009, and Java 6 reached EOL in February, 2013: I think we should ask on the community if there is any reason why JUnit should continue to support Java 5. |
Hello, @adam-beneschan When I was looking at issue #388 I noticed that both The recent changes to It couldn't hurt to make The changes to the Perhaps
|
@kcooney there is still a lot of old code out there needs to run with Java 1.5 and thus should be testable with Java 1.5; and now it gets really extreme: in the company I am working for we are developing a product called dynaTrace that must be still Java 1.4.2 compatible, because clients are using it inside their Java 1.4.2 applications... |
@adam-beneschan and @dsaff et al. I really like this new feature's direction! A few years ago we were implementing kind of related features in admittedly quite proprietary and quite ugly manner (due to being based on JUnit 4.4: no Rules!), and below I try to list some thoughts and extension ideas:
I would be very happy, if the implementation of this issue and/or supplementing issues could take these thoughts/ideas into account. Thanks, Reinhold |
I can't address all of your issues at one time, but for just the first one, one thing that might help is if Timeout#createTimeoutException were protected, so that you or anyone could create your own subclass of Timeout that would gather whatever data you wanted at the time of a timeout. If you wanted to put together a pull request for that, I'd be on-board. |
@dsaff alright, that sounds like a plan: I am going to have a look at this in the course of either this or next week |
Oh wow! #463 looks very familiar to my comments... |
@dsaff: Since the Timeout#createTimeoutException is now (?) in FailOnTimeout#createTimeoutException (statement) it would require to (1) subclass FailOnTimeout to override FailOnTimeout#createTimeoutException and (2) subclass Timeout to override Timeout#apply to create and return an instance of the new FailOnTimeout sublcass from before. I had hoped for more convenience... Besides that I also stumbled over the fact that quite some interesting thread dump information (locks, monitors, synchronizers) can only be retrieved from ThreadMXBean from Java >= 1.6. Thus, what do you think of the following naive and admittedly ugly thoughts, when I want to have this extended thread dump?
(See also my first naive pull request for #463 for discussion) |
Have you tried doing what you laid out in paragraph 1? Was it as difficult as you feared? |
I was thinking about "(1) subclass FailOnTimeout to override FailOnTimeout#createTimeoutException and (2) subclass Timeout to override Timeout#apply to create and return an instance of the new FailOnTimeout sublcass from before" This doesn't feel overly onerous to me. I was curious if you'd tried it and found it more difficult than I suspected. |
@dsaff: Okay, sorry for my confustion => now I tried... I think that in addition to these 2 steps, it is also necessary: I have made the changes and added tests to a branch (but not made a pull request yet): https://github.com/reinholdfuereder/junit/compare/customtimeout-and-customfailontimeout (Side note: in case CustomTimeoutTest.infiniteLoopwithLookForStuckThread() is executed before CustomTimeoutTest.infiniteLoop() the full stacktrace on timeout of the second test shows the surviving threads from the first test, which is using InfiniteLoopMultithreaded from the original TimeoutTest => presumably that is not on purpose...) However, please note that (as I tried to convey in the older pull requests #770 and #772) I am still hoping for "more" allowing to cover these outlined real world use cases (in particular without the risk of missing certain tests). |
changes to address kcooney's concerns about thread safety on issue #742
New class: ExceptionWithThread.java (subclass of Exception that keeps information about some other relevant thread). Changed: FailOnTimeout.java (starts test in a new ThreadGroup; on timeout, looks at running threads in ThreadGroup to see which one it thinks got stuck, creates an ExceptionWithThread if it finds one); Failure.java (displays stack for the "relevant thread" if it handles an ExceptionWithThread)