-
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
Change the Timeout rule to never timeout the test if zero is passed in. Fixes #875 #876
Conversation
Looks good, fixes my test case. It does change a bit of behavior from 4.7-4.11. In those, a negative timeout would cause an error. With this change, negative will be interpreted as "no timeout." Since that's the same thing the Test annotation's timeout does, it seems fine. Worth noting though. Is it worth adding a note in the documentation for Test and Timeout that a non-positive timeout means to wait forever? |
Thanks for the fix. Note with this change, if timeout is zero, the test will run in the same thread. In 4.7 it still ran in a different thread. I think we should instead treat zero as if they passed in MAX_INT |
Also, could you put in a more useful description? See http://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message Thanks! |
Would that be MAX_INT seconds or millis? |
We could instead update FailOnTimeout's getResult:
That would get you execution in a different thread and behavior consistent with the Test annotation. |
Updated. I had not considered Sean's suggestion, but can do that instead if it is deemed preferable. |
@madrob I think Sean's suggestion was much better than mine; his works regardless of the units passed in. My only concern with fixing this |
@kcooney In 4.7 Was there a different concern you had? |
Implemented in 14ecb4b and already pushed. |
lgtm |
+1 |
@@ -55,7 +55,11 @@ public void evaluate() throws Throwable { | |||
*/ | |||
private Throwable getResult(FutureTask<Throwable> task, Thread thread) { | |||
try { | |||
return task.get(fTimeout, fTimeUnit); | |||
if (fTimeout > 0) { | |||
return task.get(fTimeout, fTimeUnit); |
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.
nit: this should be indented one more space (we use a four-space indent in JUnit)
LGTM with one very minor style comment. Thanks! |
Fixes junit-team#875 In versions 4.7 through 4.11 setting up a Timeout @rule with a value of 0 would result in no timeout. In 4.12 FailOnTimeout switched to using FutureTask.get(timeout). That method treats non-positive timeouts to mean "timeout right now". This fix checks that the timeout value is positive before using it, and otherwise will wait indefinitely.
Indent fixed in c52397d. Somehow I managed to accidentally sneak a tab in there earlier. |
Thanks! |
Change the Timeout rule to never timeout the test if zero is passed in. Fixes #875
@madrob Could you please make a note at https://github.com/junit-team/junit/wiki/4.12-release-notes |
Done, how's that look? |
The comments above discuss subtle differences with earlier versions of JUnit. Not sure which of those are applicable to the code that was eventually merged (didn't check), but I think that the current release notes entry is not particularly useful:
A regular user upgrading from JUnit 4.11 to 4.12 will conclude that "nothing changed for me" and wonder why such implementation details are mentioned in the release notes. (@madrob effectively just caught a regression and fixed it in time.) Can we instead document the ways in which timeouts are now handled differently, if at all, and otherwise omit this from the release notes? |
@Stephan202 good point. I removed the text about this pull from the release notes. |
We missed to add it before we released JUnit 4.12. I think it may be still helpful when someone reads the old release notes.
We missed to add it before we released JUnit 4.12. I think it may be still helpful when someone reads the old release notes.
We missed to add it before we released JUnit 4.12. I think it may be still helpful when someone reads the old release notes.
No description provided.