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

Mark ThreadGroups created by FailOnTimeout as daemon groups #1687

Merged
merged 6 commits into from Jan 2, 2021

Conversation

kcooney
Copy link
Member

@kcooney kcooney commented Jan 1, 2021

Fixes #1652

…out.java


Clarify comment in FailOnTimeout.

Co-authored-by: Stefan Birkner <github@stefan-birkner.de>
@kcooney
Copy link
Member Author

kcooney commented Jan 2, 2021

FYI: I updated the test to verify that the ThreadGroup is destroyed (and verified by hand that if I don't mark it as a daemon, the ThreadGroup is not destroyed).

@kcooney
Copy link
Member Author

kcooney commented Jan 2, 2021

So apparently marking the ThreadGroup as a daemon will not result in it being destroyed in all versions of the JDK (at least not immediately after the only thread in the group completes). I'm guessing that in some versions of the JDK it would be destroyed after a delay.

@marcphilipp
Copy link
Member

Which versions did you try?

@kcooney
Copy link
Member Author

kcooney commented Jan 2, 2021

It was a race condition. The test needed to join on the inner thread before checking the ThreadGroup status.

Lots of changes to squash, but leaving as-is for now so you can all see the changes.

@stefanbirkner
Copy link
Contributor

@kcooney Can you please have a look at #1690. I changed the test that checks that the thread group is destroyed. IMO it is now checking the behavior that we are looking for. What do you think? It you are ok with the new test then your PR can be reduced to the change in FailOnTimeout and does not need to change the test.

@kcooney
Copy link
Member Author

kcooney commented Jan 2, 2021

@stefanbirkner the test in this pull now verifies that the thread group is destroyed. It has a few unnecessary assertions (I was trying to determine why it passed on my machine but not in the CI build). I would be happy to remove the now-unnecessary extra assertions (Edit: I pushed a commit to remove the unnecessary assertions).

Even so, the test in this pull seems a bit more straight-forward than the one in yours. WDYT?

@stefanbirkner
Copy link
Contributor

I tend to like your approach more. If I change my opinion I can still create another PR.

@kcooney kcooney merged commit 1254795 into junit-team:main Jan 2, 2021
@kcooney kcooney deleted the daemon-thread-group branch January 2, 2021 22:09
@stefanbirkner
Copy link
Contributor

I changed the explanation in #1690 and removed changing the test.

} catch (IllegalThreadStateException e) {
// If a thread from the group is still alive, the ThreadGroup cannot be destroyed.
// Swallow the exception to keep the same behavior prior to this change.
threadGroup.setDaemon(true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a comment here pointing to this pull request and explaining why they should be daemon.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1691 adds an explanation

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly does. Thanks.

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

Successfully merging this pull request may close these issues.

Timeout ThreadGroups should not be destroyed
4 participants